Developer-focused guide for converting multiple URLs to PDFs programmatically using the Pretty PDF API.
Free tier available — 3 PDFs per month. No credit card required.
Manually converting webpages to PDF one at a time works for the occasional save. But when you need to convert dozens or hundreds of pages, manual conversion does not scale. The Pretty PDF API lets you automate bulk webpage to PDF conversion programmatically.
Preserve entire documentation sites or knowledge bases as PDF snapshots. Capture versioned docs before they change, ensuring your team always has a reference copy of the content as it existed at a specific point in time.
Regulatory and legal teams need timestamped records of web content. Batch convert pages for audit trails, terms of service archives, or regulatory filings. PDFs provide tamper-evident records that hold up to scrutiny.
Websites go down, articles get deleted, and content changes without notice. Batch converting your important references to PDF ensures you have a permanent offline copy that does not depend on the original server being available.
Automate the creation of weekly or daily PDF reports from dashboards, analytics pages, or status boards. Schedule a script to run on a cron job and generate formatted PDFs that can be emailed to stakeholders automatically.
Three steps to go from zero to your first batch conversion. The Pretty PDF API uses standard REST conventions with API key authentication.
Sign up for a Pretty PDF account, then navigate to the developer dashboard to generate your API key. The key is passed via the X-API-Key header on every request. Keep it secret and never commit it to version control.
Test the API with a single URL before writing any code. The curl command below sends a URL to the API and saves the resulting PDF to disk. If this works, you are ready to scale up.
Once your first call succeeds, wrap it in a loop. Use Python, JavaScript, or shell scripting to iterate through a list of URLs and convert each one to PDF. Add error handling and rate limit awareness for production use.
curl -X POST https://api.prettypdfprinter.com/v1/generate/url \
-H "X-API-Key: your_api_key_here" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/page-to-convert", "template": "clean"}' \
--output page.pdf
This sends the target URL to the Pretty PDF API, applies the "clean" template, and saves the generated PDF as page.pdf. Replace your_api_key_here with your actual API key.
A complete Python example using the requests library to batch convert a list of URLs to PDF. This script handles errors gracefully and adds a delay between requests to respect rate limits.
import requests
import time
import os
API_KEY = os.environ["PRETTYPDF_API_KEY"]
API_URL = "https://api.prettypdfprinter.com/v1/generate/url"
OUTPUT_DIR = "pdfs"
urls = [
"https://example.com/docs/getting-started",
"https://example.com/docs/api-reference",
"https://example.com/docs/authentication",
"https://example.com/docs/rate-limits",
"https://example.com/blog/release-notes",
]
os.makedirs(OUTPUT_DIR, exist_ok=True)
for i, url in enumerate(urls):
print(f"[{i+1}/{len(urls)}] Converting: {url}")
try:
response = requests.post(
API_URL,
headers={
"X-API-Key": API_KEY,
"Content-Type": "application/json",
},
json={
"url": url,
"template": "clean",
},
timeout=60,
)
response.raise_for_status()
filename = url.rstrip("/").split("/")[-1] + ".pdf"
filepath = os.path.join(OUTPUT_DIR, filename)
with open(filepath, "wb") as f:
f.write(response.content)
print(f" Saved: {filepath}")
except requests.exceptions.RequestException as e:
print(f" Error: {e}")
# Respect rate limits
time.sleep(2)
Set your API key as an environment variable (export PRETTYPDF_API_KEY=your_key) before running the script. The 2-second delay between requests keeps you within standard rate limits. For larger batches, increase the delay or implement exponential backoff on 429 responses.
A Node.js script using the built-in fetch API (Node 18+) to batch convert webpages to PDF. Processes URLs sequentially with error handling and file output.
import { writeFile, mkdir } from "node:fs/promises";
const API_KEY = process.env.PRETTYPDF_API_KEY;
const API_URL = "https://api.prettypdfprinter.com/v1/generate/url";
const OUTPUT_DIR = "pdfs";
const urls = [
"https://example.com/docs/getting-started",
"https://example.com/docs/api-reference",
"https://example.com/docs/authentication",
];
await mkdir(OUTPUT_DIR, { recursive: true });
for (let i = 0; i < urls.length; i++) {
const url = urls[i];
console.log(`[${i + 1}/${urls.length}] Converting: ${url}`);
try {
const response = await fetch(API_URL, {
method: "POST",
headers: {
"X-API-Key": API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: url,
template: "clean",
}),
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const buffer = Buffer.from(await response.arrayBuffer());
const filename = url.split("/").filter(Boolean).pop() + ".pdf";
await writeFile(`${OUTPUT_DIR}/${filename}`, buffer);
console.log(` Saved: ${OUTPUT_DIR}/${filename}`);
} catch (error) {
console.error(` Error: ${error.message}`);
}
// Respect rate limits
await new Promise((resolve) => setTimeout(resolve, 2000));
}
Run with PRETTYPDF_API_KEY=your_key node convert.mjs. This uses ES module syntax and the native fetch API available in Node.js 18 and later. For older Node versions, use the node-fetch package instead.
Once your batch conversion script works, automate it to run on a schedule. Here are three common approaches for production use.
Schedule your Python or Node.js script to run daily, weekly, or monthly using cron (Linux/macOS) or Task Scheduler (Windows). A cron entry like 0 2 * * 1 runs your batch conversion every Monday at 2 AM, generating a fresh set of PDF archives automatically.
Add a PDF generation step to your CI/CD pipeline. Use a GitHub Actions workflow to convert documentation pages to PDF on every release or on a schedule. Store the API key as a repository secret and upload generated PDFs as build artifacts.
Trigger batch conversions from external events. When your CMS publishes new content, a webhook can call your conversion script to generate PDFs of the updated pages. This keeps your PDF archive in sync with your live content without manual intervention.
The Pretty PDF API uses per-minute rate limiting to ensure fair usage across all users. Your rate limit depends on your subscription tier.
Free accounts include 3 PDF conversions per month, which is enough to test the API and verify it meets your needs. Paid plans unlock higher monthly limits and faster per-minute throughput for batch workloads.
When your script hits a rate limit, the API returns a 429 Too Many Requests response. Implement exponential backoff in your code: wait 2 seconds after the first 429, then 4 seconds, then 8 seconds, and so on. Most batch scripts will not hit rate limits if you include a 2-second delay between requests.
For detailed pricing and rate limit information, see the pricing page. For enterprise batch conversion needs with higher throughput, contact support.
Full API documentation is available at api.prettypdfprinter.com/docs.
Automate your PDF generation workflow with the Pretty PDF API. Convert hundreds of URLs to professionally styled PDFs with a few lines of code.
Get Your API Key