Skip to main content

Quick Start for Rust

Rust

Rust has libraries for PDF generation and browser automation, but they often involve complex low-level APIs and setup requirements. PDFBolt's PDF generation API offers a streamlined HTTP-based approach for generating PDFs from HTML, URLs, and dynamic templates that integrates seamlessly with Rust's ecosystem.

1. Get Your API Key

  • After signing up, locate your API Key in the Admin Dashboard under the API Keys section.
  • This key is essential for authorizing your requests to the PDFBolt API. Remember to keep it secure.

2. Make Your First Request

Configure your requests using these examples to integrate with the PDFBolt API and generate PDFs.

Choose your preferred endpoint and source combination.

➡️ Endpoints:

The Direct endpoint provides immediate PDF generation and returns the raw PDF file in the response.


➡️ Sources:

Convert any webpage into a PDF:

use reqwest::{Client, Method, header::HeaderMap};
use serde_json::json;
use std::fs;

pub async fn make_request() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let url = "https://api.pdfbolt.com/v1/direct";

let mut headers = HeaderMap::new();
headers.insert("API-KEY", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX".parse().unwrap());
headers.insert("Content-Type", "application/json".parse().unwrap());

let response = client.request(Method::POST, url)
.headers(headers)
.json(&json!({
"url": "https://example.com",
"format": "A4",
"printBackground": true
}))
.send()
.await?;

if !response.status().is_success() {
println!("HTTP {}", response.status().as_u16());
let error_text = response.text().await?;
println!("Error Message: {}", error_text);
return Ok(());
}

let pdf_bytes = response.bytes().await?;
fs::write("webpage.pdf", pdf_bytes)?;

println!("PDF generated successfully");
Ok(())
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
make_request().await?;
Ok(())
}

3. What's next?

Discover how PDFBolt can enhance your Rust applications. Start with the API Endpoints and explore the Conversion Parameters to tailor your integration for your specific needs.