Use Case Guide · Updated February 2026
HTML to PDF API: Convert Web Pages to PDF
Generating PDFs from web content is one of the most common developer tasks — and one of the most painful. Invoices, reports, certificates, dashboards — they all need pixel-perfect PDF output from HTML/CSS. Running wkhtmltopdf or headless Chrome yourself means managing servers, dealing with font rendering issues, and fighting CSS print styles. A PDF generation API eliminates all of that.
📄 HTML to PDF in One API Call
Convert any URL or HTML to PDF. Custom sizes, headers, footers. 200 free/month.
Get Free API Key →Generate PDFs from URLs
curl
curl "https://api.snapapi.pics/v1/pdf?url=https://example.com/invoice/123" \
-H "Authorization: Bearer YOUR_API_KEY" \
-o invoice.pdf
With Custom Options
curl "https://api.snapapi.pics/v1/pdf?url=https://example.com/report&paperWidth=8.5&paperHeight=11&marginTop=1&marginBottom=1&printBackground=true" \
-H "Authorization: Bearer YOUR_API_KEY" \
-o report.pdf
Node.js — Invoice Generation
async function generateInvoice(invoiceId) {
const response = await fetch(
`https://api.snapapi.pics/v1/pdf?` +
`url=${encodeURIComponent(`https://app.yoursite.com/invoices/${invoiceId}`)}` +
`&paperWidth=8.5&paperHeight=11&printBackground=true`,
{ headers: { 'Authorization': 'Bearer YOUR_API_KEY' } }
);
const pdfBuffer = Buffer.from(await response.arrayBuffer());
// Save or email the invoice
await fs.promises.writeFile(`invoices/${invoiceId}.pdf`, pdfBuffer);
return pdfBuffer;
}
Python — Report Generation
import requests
def generate_report_pdf(report_url, output_path):
response = requests.get(
'https://api.snapapi.pics/v1/pdf',
params={
'url': report_url,
'paperWidth': 8.5,
'paperHeight': 11,
'marginTop': 0.5,
'marginBottom': 0.5,
'printBackground': True
},
headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
with open(output_path, 'wb') as f:
f.write(response.content)
return output_path
# Generate a dashboard PDF
generate_report_pdf('https://app.yoursite.com/dashboard', 'dashboard.pdf')
PDF Generation: API vs DIY
| Aspect | DIY (wkhtmltopdf / Puppeteer) | SnapAPI |
|---|---|---|
| Setup | Install Chrome/wkhtmltopdf, manage deps | Zero setup — API call |
| Font rendering | Install fonts on server, font issues common | Full web font support |
| CSS support | wkhtmltopdf: outdated WebKit; Puppeteer: full | Full modern CSS (Chromium) |
| JavaScript rendering | wkhtmltopdf: limited; Puppeteer: full | Full JS execution |
| Memory usage | 500MB+ per Chrome instance | Zero — serverless |
| Concurrent generation | Complex queue management | Auto-scaling |
| Print CSS support | Varies by tool | Full @media print support |
Common PDF Generation Use Cases
🧾 Invoices & Receipts
Generate professional invoices from HTML templates. Consistent rendering across all platforms.
📊 Reports & Dashboards
Convert data dashboards to shareable PDFs. Charts, tables, and graphs render perfectly.
📜 Certificates
Generate personalized certificates, diplomas, and awards from templates at scale.
📋 Contracts & Documents
Create legal documents, proposals, and contracts from structured data and templates.
PDF Generation Tips
- Use
@media printCSS — hide navigation, ads, and non-essential elements in your print stylesheet - Set
printBackground=true— without this, background colors and images won't render - Use proper paper sizes — US Letter (8.5×11"), A4 (8.27×11.69"), or custom dimensions in inches
- Add page breaks — use
page-break-before: alwaysCSS to control multi-page layouts - Test with web fonts — ensure your fonts load before the PDF is generated (SnapAPI waits for network idle)
- Use
waitForSelector— if your page has dynamic content, wait for a specific element to ensure it's loaded
Advanced: HTML String to PDF
Don't want to host a template page? You can send HTML directly:
curl -X POST "https://api.snapapi.pics/v1/pdf" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"html": "<html><body style=\"font-family: Arial; padding: 40px;\"><h1>Invoice #1234</h1><p>Amount: $99.00</p></body></html>",
"paperWidth": 8.5,
"paperHeight": 11
}' \
-o invoice.pdf
FAQ
What paper sizes are supported?
Any custom size in inches. Common presets: US Letter (8.5×11"), A4 (8.27×11.69"), Legal (8.5×14"). Set paperWidth and paperHeight parameters.
Can I add headers and footers to PDFs?
Yes. Use the headerTemplate and footerTemplate parameters with HTML. You can include page numbers, dates, and custom text.
Does it support JavaScript-rendered content?
Yes. SnapAPI uses a full Chromium browser, so React, Vue, Angular, and any JavaScript framework renders correctly before PDF generation.
How long does PDF generation take?
Typically 2-5 seconds depending on page complexity. Simple pages are under 2 seconds. Pages with heavy JavaScript or many images take longer.
Related: Free Screenshot API · Web Archiving API · API Documentation