Guide

Batch Convert Webpages to PDF — Automate at Scale

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.

The problem

Why batch conversion?

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.

Documentation archival

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.

Compliance snapshots

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.

Content backups

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.

Weekly report generation

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.

Getting started

Getting started with the API

Three steps to go from zero to your first batch conversion. The Pretty PDF API uses standard REST conventions with API key authentication.

1

Get your API key from the dashboard

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.

2

Make your first API call with curl

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.

3

Scale up with batch scripts

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.

Example: Single URL conversion with curl

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.

Python

Python script for bulk conversion

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.

JavaScript

JavaScript / Node.js example

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.

Advanced

Scheduling and automation

Once your batch conversion script works, automate it to run on a schedule. Here are three common approaches for production use.

Cron jobs for regular archival

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.

CI/CD integration with GitHub Actions

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.

Webhook triggers

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.

Pricing

API rate limits and pricing

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.

Frequently asked questions about batch PDF conversion

Yes. The Pretty PDF API accepts one URL per request, but you can send multiple requests in sequence or in parallel to convert a batch of URLs to PDF. Use a script in Python, JavaScript, or any language that supports HTTP requests. Loop through your list of URLs, call the /v1/generate/url endpoint for each one, and save the resulting PDF files. For large batches, add a short delay between requests to stay within rate limits.
Yes. Pretty PDF Printer provides a REST API at api.prettypdfprinter.com. The /v1/generate/url endpoint accepts a URL and returns a styled PDF. You can also send raw HTML to /v1/generate for full control over the input. Authentication is via API key passed in the X-API-Key header. The API supports template selection, page size configuration, and custom profiles.
Rate limits depend on your subscription tier. Free accounts are limited to 3 PDFs per month. Paid plans include higher rate limits with per-minute throttling to ensure fair usage. When you exceed the rate limit, the API returns a 429 status code. Implement exponential backoff in your scripts to handle this gracefully. Check the pricing page or API documentation for current limits.
Yes. The API accepts a template parameter that lets you choose from five built-in CSS templates: clean, minimal, corporate, academic, and dark. You can also specify page size (A4, Letter, Legal) and select a profile for further customization. All template options available in the Chrome extension are also available through the API.
The Pretty PDF API is a standard REST API, so it works with any programming language that can make HTTP requests. This guide includes examples in Python (using the requests library), JavaScript/Node.js (using fetch), and curl for shell scripting. You can also use Ruby, Go, Java, PHP, C#, or any other language with an HTTP client library.

Start batch converting webpages to PDF today

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