← Back to Blog

Generate PDF from URL with an API: Complete Guide

March 14, 2026 -- 10 min read

Need to convert web pages to PDF automatically? Whether you are generating invoices, archiving content, creating reports, or building export features, a PDF generation API lets you do it with a single HTTP request. This guide covers everything from basic usage to advanced configuration.

Why Use an API for PDF Generation?

While libraries like wkhtmltopdf or Puppeteer can render PDFs locally, a managed API offers significant advantages:

Quick Start: Your First PDF

The simplest way to generate a PDF from a URL is a single cURL command:

curl "https://screenshotapi-api-production.up.railway.app/v1/pdf\
  ?url=https://example.com" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -o page.pdf

This generates an A4 PDF of example.com and saves it as page.pdf.Get your free API key to try it.

Node.js Example

Using our official SDK, PDF generation is just a few lines:

const ScreenshotAPI = require('screenshotapi-sdk');
const fs = require('fs');

const client = new ScreenshotAPI('YOUR_API_KEY');

// Generate a PDF
const pdf = await client.pdf('https://example.com', {
  format: 'A4',
  landscape: false,
  background: true,
});

fs.writeFileSync('page.pdf', pdf);
console.log('PDF saved!');

Install with: npm install screenshotapi-sdk

Python Example

import requests

API_KEY = 'YOUR_API_KEY'
BASE_URL = 'https://screenshotapi-api-production.up.railway.app'

response = requests.get(
    f'{BASE_URL}/v1/pdf',
    params={
        'url': 'https://example.com',
        'format': 'A4',
        'background': 'true',
    },
    headers={'Authorization': f'Bearer {API_KEY}'},
)

with open('page.pdf', 'wb') as f:
    f.write(response.content)

print(f'PDF saved ({len(response.content)} bytes)')

API Parameters

Customize your PDF output with these parameters:

ParameterDefaultDescription
urlrequiredThe URL to convert to PDF
formatA4Paper format: A4, Letter, Legal, Tabloid
landscapefalseLandscape orientation
backgroundtruePrint background colors and images
wait0Wait time in ms before capture (for dynamic content)

Common Use Cases

1. Invoice Generation

Build your invoice as an HTML page (with CSS for print styles), then convert it to PDF via the API. This approach gives you full design control with web technologies while producing a professional PDF output.

// Generate invoice PDF from a dynamic URL
const invoicePdf = await client.pdf(
  'https://yourapp.com/invoices/INV-2026-001',
  { format: 'A4', background: true }
);

2. Content Archiving

Archive web pages, articles, or documentation as PDFs for offline access or legal compliance. The API captures the full rendered page including images, styles, and dynamic content.

3. Report Export

Let users download dashboards, analytics, or data visualizations as PDF reports. Build the report view as a web page, then use the API to generate a downloadable PDF.

4. E-commerce Order Confirmations

Generate PDF order confirmations, packing slips, or shipping labels from dynamic web pages. Each order gets its own URL, and the API converts it to a clean PDF.

Tips for Better PDFs

Pricing

PDF generation uses the same credits as screenshots. Each API call counts as one request:

See full pricing details.

API vs Self-Hosted: When to Use Each

FactorAPI (ScreenshotAPI)Self-Hosted (Puppeteer)
Setup time5 minutes1-2 days
InfrastructureNone neededDocker, Chrome, server
MaintenanceZeroOngoing updates
Cost at 1K/mo$0 (free tier)$20-50/mo server
Cost at 50K/mo$99/mo$200-500/mo
Reliability99.9% uptime SLADepends on your ops

For a detailed comparison, read our Puppeteer vs API guide.

Getting Started

Ready to generate your first PDF? Here is how to start:

  1. Create a free account (takes 30 seconds)
  2. Copy your API key from the dashboard
  3. Make your first API call using the examples above
  4. Explore the full API documentation for advanced options

Start Generating PDFs Today

100 free PDFs per month. No credit card required.