HTML to PDF API: Generate PDFs from Any Web Page
Convert any URL or HTML page to PDF using SnapAPI. Full Chromium rendering — JavaScript, CSS, web fonts, charts. A4, Letter, custom margins. No library installs.
HTML to PDF via API — No Headless Browser Required
Generating PDFs from HTML is one of the most requested features in backend development and one of the most painful to implement correctly. Libraries like wkhtmltopdf, Puppeteer, or WeasyPrint each bring their own installation requirements, CSS rendering quirks, and server resource overhead. SnapAPI's PDF endpoint replaces all of this with a single HTTP call: send a URL or raw HTML, receive a PDF.
Generate a PDF from a URL
# Python
import requests
resp = requests.get(
"https://api.snapapi.pics/v1/pdf",
params={
"url": "https://example.com/invoice/123",
"format": "A4",
"margin_top": "20mm",
"margin_bottom": "20mm",
"print_background": "true",
},
headers={"X-Api-Key": "YOUR_API_KEY"}
)
with open("invoice.pdf", "wb") as f:
f.write(resp.content)
print(f"PDF size: {len(resp.content)} bytes")SnapAPI renders the URL in a full Chromium browser — JavaScript executes, CSS loads, web fonts render, charts draw — before printing to PDF. This means your existing HTML invoice template, dashboard export page, or report view works exactly as designed, without adapting it for a PDF library's limited CSS support.
PDF Page Formats and Options
Supported page formats include A4, A3, Letter, Legal, Tabloid, and custom dimensions via width and height. Control margins with margin_top, margin_right, margin_bottom, and margin_left in mm or px. Set print_background=true to include background colors and images (required for branded report headers), and landscape=true for wide tables or dashboards that need horizontal layout.
Combine with the css parameter to inject print-specific styles before capture: hide navigation bars, expand collapsed sections, apply print-safe fonts, and remove interactive elements that have no meaning in a static document. This gives you pixel-perfect PDF output from pages originally designed for browser display.
PDF Generation Use Cases
The most common production use cases for HTML-to-PDF APIs include: invoice and receipt generation from web-based billing systems, downloadable report exports from analytics dashboards, contract and agreement PDF delivery from document management platforms, print-ready product catalogs generated from CMS content, and regulatory compliance documents that must be archived in PDF/A format.
For each of these, the HTML-to-PDF approach via SnapAPI is superior to template-based PDF libraries because you write and maintain a single HTML template — styled with standard CSS, tested in a browser — rather than constructing the document programmatically through a PDF library's bespoke layout API.
Get started at snapapi.pics with 200 free PDF captures per month. No library installations, no Chromium binaries to manage, no server resources consumed by headless browsers. Your PDF generation pipeline runs as a stateless HTTP integration that scales automatically with your usage.