Skip to main content

Quick Start for Python

Python

Python offers several libraries for PDF generation, but they can be complex to set up and configure. Our PDF generation API provides a simpler, more flexible way to generate PDFs from HTML, URLs, and dynamic templates. Here's how to start in Python.

1. Get Your API Key

  • After registering, log in to the Admin Dashboard and navigate to the API Keys section to retrieve your API key.
  • Ensure you keep this key secure, as it is essential for authorizing your requests to the PDFBolt API.

2. Make Your First Request

Use these examples to make requests to the PDFBolt API and generate PDFs quickly.

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:

import requests
import json

url = "https://api.pdfbolt.com/v1/direct"
headers = {
"API-KEY": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"Content-Type": "application/json"
}

data_json = '''{
"url": "https://example.com",
"format": "A4",
"printBackground": true
}'''

data = json.loads(data_json)

try:
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()

with open('webpage.pdf', 'wb') as f:
f.write(response.content)
print("PDF generated successfully")

except requests.exceptions.HTTPError as e:
print(f"HTTP {response.status_code}")
print(f"Error Message: {response.text}")
except requests.exceptions.RequestException as e:
print(f"Error: {e}")

3. What's next?

Continue your journey with PDFBolt by exploring its powerful features and benefits. Start by checking the available API Endpoints and dive into the Conversion Parameters to customize your integration for your unique needs.