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:
- No infrastructure -- No need to manage headless browsers, Chrome installations, or Docker containers
- Consistent rendering -- Same Chrome engine on every request, no version mismatches
- Scalability -- Handle 10 or 10,000 PDFs without provisioning servers
- Modern CSS support -- Full support for flexbox, grid, web fonts, and CSS3
- Maintenance-free -- No browser updates, security patches, or dependency conflicts
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.pdfThis 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:
| Parameter | Default | Description |
|---|---|---|
url | required | The URL to convert to PDF |
format | A4 | Paper format: A4, Letter, Legal, Tabloid |
landscape | false | Landscape orientation |
background | true | Print background colors and images |
wait | 0 | Wait 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
- Use CSS print styles -- Add
@media printrules to hide navigation, sidebars, and other non-essential elements. - Set explicit page breaks -- Use
page-break-beforeandpage-break-afterCSS properties to control pagination. - Wait for dynamic content -- If the page loads data asynchronously, use the
waitparameter (e.g., 2000ms) to ensure content is rendered. - Enable background printing -- Set
background=trueto include background colors and images in the PDF. - Use web fonts -- The API supports Google Fonts and other web fonts. Ensure fonts are loaded before the PDF is generated.
Pricing
PDF generation uses the same credits as screenshots. Each API call counts as one request:
- Free tier: 100 PDFs/month -- perfect for testing and small projects
- Pro ($29/mo): 10,000 PDFs/month -- for production applications
- Business ($99/mo): 100,000 PDFs/month -- for high-volume use cases
See full pricing details.
API vs Self-Hosted: When to Use Each
| Factor | API (ScreenshotAPI) | Self-Hosted (Puppeteer) |
|---|---|---|
| Setup time | 5 minutes | 1-2 days |
| Infrastructure | None needed | Docker, Chrome, server |
| Maintenance | Zero | Ongoing updates |
| Cost at 1K/mo | $0 (free tier) | $20-50/mo server |
| Cost at 50K/mo | $99/mo | $200-500/mo |
| Reliability | 99.9% uptime SLA | Depends 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:
- Create a free account (takes 30 seconds)
- Copy your API key from the dashboard
- Make your first API call using the examples above
- Explore the full API documentation for advanced options
Start Generating PDFs Today
100 free PDFs per month. No credit card required.