Home โ†’ Blog โ†’ URL to PDF API

URL to PDF API โ€” Generate PDFs from Any Website

Published April 2026 ยท 9 min read ยท Updated April 2026

Need to convert a URL to PDF programmatically? Whether you're generating invoices from a web template, archiving web pages for compliance, creating printable reports from dashboards, or building an export-to-PDF feature, a URL to PDF API lets you turn any webpage into a pixel-perfect PDF document with a single HTTP request.

GetScreenshot.dev includes a fully-featured HTML to PDF API on every plan โ€” including the free tier. No separate service, no extra credits. In this guide, we'll cover use cases, walk through code examples, and break down every PDF generation feature available.

Why Use an API Instead of Self-Hosting?

You could run a headless browser yourself with Puppeteer or Playwright and call page.pdf(). But there are real reasons developers choose an API instead:

  • No infrastructure. Headless Chrome requires 500MBโ€“2GB of RAM per instance. Scaling to handle concurrent PDF generation means running Kubernetes pods, managing memory limits, and handling crashes. An API makes it someone else's problem.
  • Consistent rendering. Fonts, CSS, and layout can render differently across operating systems and browser versions. A managed API ensures consistent output regardless of your server environment.
  • JavaScript execution. Modern web pages rely heavily on JavaScript. The API runs a full Chromium instance, waiting for JS to execute, SPAs to render, and lazy content to load before generating the PDF.
  • Edge case handling. Cookie consent banners, authentication walls, dynamic content, web fonts โ€” a good PDF API handles all of these out of the box.

Code Examples: Generate a PDF from a URL

Here's how to convert any URL to a PDF using GetScreenshot's API. Replace YOUR_API_KEY with your actual key.

curl

curl
# Basic URL to PDF
curl -o document.pdf \
  "https://api.getscreenshot.dev/v1/pdf?url=https://example.com" \
  -H "X-API-Key: YOUR_API_KEY"

# A4 paper with custom margins
curl -o report.pdf \
  "https://api.getscreenshot.dev/v1/pdf?url=https://example.com&paperWidth=8.27&paperHeight=11.69&marginTop=1&marginBottom=1&marginLeft=0.5&marginRight=0.5" \
  -H "X-API-Key: YOUR_API_KEY"

# Print background graphics
curl -o styled.pdf \
  "https://api.getscreenshot.dev/v1/pdf?url=https://example.com&printBackground=true" \
  -H "X-API-Key: YOUR_API_KEY"

Python

Python
import requests

API_KEY = "YOUR_API_KEY"

def url_to_pdf(url, filename="output.pdf", **options):
    """Convert any URL to PDF via GetScreenshot API."""
    params = {
        "url": url,
        "printBackground": "true",
        **options
    }
    response = requests.get(
        "https://api.getscreenshot.dev/v1/pdf",
        params=params,
        headers={"X-API-Key": API_KEY}
    )
    response.raise_for_status()

    with open(filename, "wb") as f:
        f.write(response.content)

    print(f"PDF saved: {filename} ({len(response.content)} bytes)")
    return filename

# Generate a basic PDF
url_to_pdf("https://example.com")

# Generate an A4 PDF with margins
url_to_pdf("https://example.com/report", "report.pdf",
    paperWidth="8.27", paperHeight="11.69",
    marginTop="1", marginBottom="1"
)

# Generate a landscape PDF
url_to_pdf("https://example.com/dashboard", "dashboard.pdf",
    landscape="true",
    paperWidth="11.69", paperHeight="8.27"
)

Node.js

Node.js
const fs = require("fs");

const API_KEY = "YOUR_API_KEY";

async function urlToPdf(url, filename = "output.pdf", options = {}) {
  const params = new URLSearchParams({
    url,
    printBackground: "true",
    ...options
  });

  const response = await fetch(
    `https://api.getscreenshot.dev/v1/pdf?${params}`,
    { headers: { "X-API-Key": API_KEY } }
  );

  if (!response.ok) {
    throw new Error(`API error: ${response.status} ${response.statusText}`);
  }

  const buffer = Buffer.from(await response.arrayBuffer());
  fs.writeFileSync(filename, buffer);
  console.log(`PDF saved: ${filename} (${buffer.length} bytes)`);
}

// Basic PDF
await urlToPdf("https://example.com");

// Invoice PDF with A4 paper
await urlToPdf("https://app.example.com/invoice/123", "invoice.pdf", {
  paperWidth: "8.27",
  paperHeight: "11.69",
  marginTop: "0.5",
  marginBottom: "0.5",
  marginLeft: "0.5",
  marginRight: "0.5"
});

PDF Generation Features

GetScreenshot's URL to PDF API gives you fine-grained control over the output. Here's everything you can configure:

Feature Parameter Description
Paper size paperWidth, paperHeight Set custom dimensions in inches (8.5ร—11 for Letter, 8.27ร—11.69 for A4)
Margins marginTop, marginBottom, marginLeft, marginRight Set page margins in inches
Landscape landscape Generate in landscape orientation
Background graphics printBackground Include CSS backgrounds and images (default: true)
Page ranges pageRanges Print specific pages (e.g., "1-3", "1,3,5")
Scale scale Scale the page content (0.1 to 2.0)
Delay delay Wait for JavaScript/animations before rendering (ms)
Dark mode darkMode Emulate dark color scheme before rendering

Use Cases for a URL to PDF API

A webpage to PDF API is surprisingly versatile. Here are the most common use cases developers build:

1. Invoice and Receipt Generation

Build your invoices as HTML/CSS templates (where they're easy to design and iterate on), then convert them to PDF for download or email attachment. This is far more maintainable than generating PDFs with libraries like wkhtmltopdf or ReportLab. Your designers can style invoices with CSS, and your backend just sends a URL to the API.

2. Report Export

Let users export dashboards, analytics reports, or data tables as PDF documents. Render the report page server-side, capture it as a PDF, and serve it as a download. Works perfectly for business intelligence tools, CRM exports, and admin panels.

3. Web Page Archiving

Archive web pages in a format that preserves layout, images, and text content. PDFs are ideal for legal compliance, regulatory requirements, and evidence preservation. They're self-contained, tamper-evident, and universally viewable.

4. Contract and Document Generation

Create contracts, proposals, or terms of service from web templates. Merge dynamic data (names, dates, amounts) into an HTML template, and convert to PDF. Each document gets a unique URL, and you get a pixel-perfect PDF.

5. Print-Ready Content

Generate print-ready documents from web content โ€” restaurant menus, event programs, product catalogs, or educational materials. Use CSS @media print rules for print-specific styling, and the API will respect them.

6. Email Attachments

Automatically generate PDF summaries, weekly digests, or order confirmations and attach them to transactional emails. Your email service sends the email; the PDF API generates the attachment.

HTML to PDF: Using Custom HTML

Don't have a public URL for your content? You can also convert raw HTML to PDF by hosting a simple template endpoint:

Express.js โ€” HTML template endpoint
// Serve dynamic invoice HTML
app.get("/invoice/:id", async (req, res) => {
  const invoice = await getInvoice(req.params.id);
  res.send(`
    <html>
    <head><style>
      body { font-family: sans-serif; padding: 40px; }
      h1 { color: #333; }
      table { width: 100%; border-collapse: collapse; }
      td, th { padding: 8px; border-bottom: 1px solid #eee; }
    </style></head>
    <body>
      <h1>Invoice #${invoice.id}</h1>
      <p>Date: ${invoice.date}</p>
      <p>Bill to: ${invoice.customer}</p>
      <table>
        <tr><th>Item</th><th>Amount</th></tr>
        ${invoice.items.map(i =>
          `<tr><td>${i.name}</td><td>$${i.amount}</td></tr>`
        ).join("")}
      </table>
      <p><strong>Total: $${invoice.total}</strong></p>
    </body></html>
  `);
});

// Generate PDF from the template
const pdfUrl = `https://api.getscreenshot.dev/v1/pdf?url=${encodeURIComponent(
  "https://yourapp.com/invoice/123"
)}&printBackground=true&paperWidth=8.27&paperHeight=11.69`;

This pattern โ€” HTML templates rendered server-side, converted to PDF via API โ€” is the most maintainable approach to document generation. It decouples design (HTML/CSS) from rendering (API) and lets you iterate on document layouts without touching backend code.

Pricing: URL to PDF API

PDF generation is included on every GetScreenshot plan at no extra cost. One PDF counts as one screenshot credit:

Plan PDFs/Month Price
Free 500 $0
Starter 3,000 $9/mo
Growth 15,000 $29/mo
Business 60,000 $79/mo
Scale 200,000 $199/mo

Most competitors charge extra for PDF generation or limit it to higher-tier plans. With GetScreenshot, PDF is a first-class citizen on every tier.

๐ŸŽฏ Summary

GetScreenshot's URL to PDF API lets you convert any webpage to a pixel-perfect PDF with a single API call. You get full control over paper size, margins, orientation, backgrounds, and page ranges. It's included on every plan (even the free tier at 500 PDFs/month), with no separate billing or add-on fees. Whether you're generating invoices, exporting reports, or archiving web pages, it just works.

Start generating PDFs for free

500 PDFs/month. No credit card. Full feature access. Sign up in 30 seconds.

Get Free API Key โ†’

Or try the live playground โ€” no signup required.