Skip to content

How to Capture a Website as PDF with an API

Step-by-step guide to converting any web page into a print-ready PDF using the ScreenshotCenter API. Covers paper format, margins, headers, footers, and background graphics.

Why use an API for PDF generation?

Browser-based PDF generation (via window.print() or wkhtmltopdf) gives you limited control over rendering. Modern SPAs, lazy-loaded images, and JavaScript-heavy layouts often produce broken PDFs. A PDF generation API renders the page in a full Chrome browser — the same engine your visitors use — and returns a pixel-perfect PDF.

Basic PDF capture

The simplest call adds pdf=true to a screenshot request:

curl "https://api.screenshotcenter.com/api/screenshot/create?url=https://example.com&pdf=true&key=YOUR_API_KEY"

This returns a PDF rendered at the default paper size (Letter) with Chrome's default margins.

Controlling paper format and orientation

Pass pdf_format to select A4, A3, Letter, Legal, or Tabloid. Add pdf_landscape=true for landscape orientation:

curl "https://api.screenshotcenter.com/api/screenshot/create?url=https://example.com&pdf=true&pdf_format=A4&pdf_landscape=true&key=YOUR_API_KEY"

Custom margins

Use pdf_margin_top, pdf_margin_bottom, pdf_margin_left, and pdf_margin_right with CSS-style values:

&pdf_margin_top=20mm&pdf_margin_bottom=20mm&pdf_margin_left=15mm&pdf_margin_right=15mm

Background graphics

By default, Chrome strips background colors and images when printing. Add pdf_background=true to preserve them — essential for marketing pages, dashboards, and reports.

Single-page PDF

Need the entire page on one continuous sheet? Use pdf_single_page=true. The paper height adjusts to fit the full rendered content — useful for long reports or invoices.

Combining with automation

PDFs work with all other API features. You can automate login steps before generating the PDF, route through a specific country, or deliver the result directly to S3 or Google Drive.

Python example

import screenshotcenter

client = screenshotcenter.Client(api_key="YOUR_API_KEY")

screenshot = client.create(
    url="https://example.com/invoice",
    pdf=True,
    pdf_format="A4",
    pdf_margin_top="20mm",
    pdf_margin_bottom="20mm",
    pdf_background=True,
)

# Download the PDF
client.download(screenshot["id"], "invoice.pdf")

See the full Python SDK documentation for all available parameters.

Next steps

For batch PDF generation (hundreds of invoices or reports), see the batch screenshot API. For automated client deliverables, read client reporting with screenshots and PDFs.