Website to PDF API: Convert Any URL to PDF Programmatically
Converting websites to PDFs programmatically is a common requirement in modern web applications — from generating invoices and receipts, to archiving web pages, creating reports, and sending documentation. This guide walks you through using a website to PDF API and shows exactly how to integrate one into your own project.
Why Use an API Instead of a DIY Solution?
You could set up your own PDF generation pipeline using Puppeteer, headless Chrome, or wkhtmltopdf. But there are real costs to consider before going that route.
Infrastructure complexity: Running headless browsers at scale requires dedicated servers, memory management, and careful concurrency handling. A single Puppeteer instance can consume 200–500 MB of RAM. For production traffic, you need to manage a pool of browser instances, handle crashes, and implement queuing.
Maintenance burden: Browser updates, dependency conflicts, and rendering bugs need constant attention. What renders correctly today may break after a Chrome or Node.js update.
A hosted PDF API handles all of this for you, letting you focus on your product rather than rendering infrastructure.
How to Convert a Website to PDF via API
Using Page Printer's REST API, you can convert any URL to a PDF with a single HTTP POST request:
const response = await fetch('https://pageprinter.zapius.online/pdf/generate', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
url: 'https://example.com',
format: 'A4',
margin: '10px',
}),
});
const pdfBuffer = await response.arrayBuffer();
// Save, upload to S3, or stream to browser downloadThe API returns the raw PDF binary. You can save it to disk, upload it to a cloud storage bucket, or stream it directly as a browser download — no additional libraries needed.
Common Use Cases
Invoice and receipt generation: Most billing systems need to produce PDFs from HTML invoice templates. Pass the invoice URL (or a localhost URL during development) directly to the API to get a pixel-perfect PDF without maintaining a separate rendering stack.
Web archiving: Journalists, researchers, and legal teams often need to archive web pages with their exact visual appearance preserved. The API captures the full rendered state including images, styles, and dynamically loaded content.
Report generation: Analytics dashboards and BI tools can convert their HTML output to PDF for distribution via email or scheduled delivery.
Documentation snapshots: Technical writers can snapshot documentation pages into PDFs for offline distribution or version archiving.
Handling Authenticated Pages
Need to capture a page behind a login? Pass the session cookie or authorization header with your request:
body: JSON.stringify({
url: 'https://your-app.com/dashboard/report',
headers: {
'Cookie': 'session=your-session-token',
},
format: 'A4',
})Key Features to Look For in a PDF API
- Full JavaScript execution — modern web apps depend on JS. The rendering engine should execute the page completely before capturing.
- Custom page formats — support for A4, Letter, and custom dimensions.
- Authentication support — cookies and headers for pages behind logins.
- Consistent rendering — the PDF should be identical to what a user sees in their browser.
DIY Puppeteer vs. a Hosted PDF API
| Consideration | DIY Puppeteer | PDF API |
|---|---|---|
| Setup time | Days | Minutes |
| RAM per instance | 200–500 MB | None |
| Maintenance | High | None |
| Rendering quality | High | High |
| Cost model | Server costs | Per-PDF credits |
Start converting websites to PDF for free
Page Printer gives you 10 free credits per month — no credit card required. Get your API key in under a minute.
Get your free API key →