Skip to main content

Quick Start for Python

Python

Integrate PDFBolt's REST API in Python to generate PDFs from URLs, HTML, or templates. The examples below cover all three conversion modes (Direct, Sync, Async).

1. Get Your API Key

Find your API key on the API Keys page in your Dashboard. If you don't have an account, sign up – the free plan includes 100 document conversions per month.

2. Make Your First Request

Any HTTP client works – adjust the request structure to match your library.

Examples use the requests library. Install it with:

pip install requests

Choose your endpoint:

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

Choose your source:

Convert a webpage to PDF:

import requests

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

data = {
"url": "https://example.com",
"format": "A4",
"printBackground": True
}

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:
print(f"HTTP {response.status_code}")
print(f"Error Message: {response.text}")
except requests.exceptions.RequestException as e:
print(f"Error: {e}")

Next Steps



Related reading