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.

Start Free — 200 captures/mo View Docs

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.

PDF Generation in Node.js

Generating PDFs from HTML in Node.js has historically been painful. Puppeteer requires a Chromium binary, html-pdf bundles wkhtmltopdf which has poor CSS support, and jsPDF requires constructing the document imperatively rather than using your existing HTML templates. SnapAPI replaces all of these with a single HTTP call from any Node.js version:

const params = new URLSearchParams({
  url: "https://your-app.com/invoices/123",
  format: "A4",
  margin_top: "15mm",
  margin_bottom: "15mm",
  margin_left: "15mm",
  margin_right: "15mm",
  print_background: "true",
});

const res = await fetch(
  `https://api.snapapi.pics/v1/pdf?${params}`,
  { headers: { "X-Api-Key": process.env.SNAPAPI_KEY } }
);

const pdfBuffer = Buffer.from(await res.arrayBuffer());
await fs.writeFile("invoice.pdf", pdfBuffer);
// or: res.setHeader("Content-Type", "application/pdf"); res.send(pdfBuffer);

The PDF endpoint accepts the same authentication as all other SnapAPI endpoints: pass your API key in the X-Api-Key header. The response body is a raw PDF byte stream — write it to disk, stream it in an HTTP response, or upload it directly to S3 or Google Cloud Storage.

Header and Footer Templates

For multi-page documents, use CSS @page rules in your page template to define headers and footers that repeat across all pages. Set display_header_footer=true and provide HTML templates for the header and footer content via the corresponding parameters. This gives you page numbers, company branding, and document metadata on every page without any post-processing of the PDF.

The wait_for parameter is especially useful for PDF generation from dashboard pages that load data asynchronously. Pass a CSS selector like .chart-loaded and SnapAPI waits until that element appears before printing, ensuring all charts and data visualizations are fully rendered in the PDF rather than capturing an empty loading state.

Every SnapAPI account starts with 200 free PDF captures per month. Sign up at snapapi.pics and generate your first PDF from an HTML page in under five minutes. No system dependencies, no Chromium binaries, no library configuration — just one HTTP call.

PDF API Comparison: SnapAPI vs Alternatives

Several options exist for HTML-to-PDF generation. Here is how they compare in practice.

wkhtmltopdf — Based on an old WebKit engine. Requires binary installation on every server. Poor support for flexbox, grid, and modern CSS. Free but maintenance-heavy and visually inaccurate on modern templates.

Puppeteer/Playwright PDF — Full Chromium rendering, excellent CSS support. Requires 200-400 MB Chromium binary, significant memory per concurrent job, and careful process lifecycle management. Best for teams that already run browser infrastructure. Not suitable for serverless or edge deployments due to binary size and memory requirements.

PDFKit / ReportLab / iTextSharp — Programmatic PDF construction. No HTML input — you describe the document imperatively through the library API. Very powerful for structured documents but requires maintaining a parallel document-building codebase alongside your HTML templates. High engineering overhead.

SnapAPI PDF endpoint — Full Chromium rendering via API call. No binary installation, no memory overhead on your servers, works from any language or runtime. Supports all modern CSS features, JavaScript rendering, custom margins, headers/footers, and page formats. Scales automatically. Starts free at 200 PDFs per month.

SnapAPI PDF Pricing

PDF generation counts against your monthly API call quota alongside screenshots and other endpoint calls. Free: 200 calls/month. Starter ($19/month): 5,000. Pro ($79/month): 50,000. Business ($299/month): 500,000. For a billing system generating 10,000 invoices monthly, the Starter or Pro plan covers the entire PDF workload at a fraction of the cost of maintaining Puppeteer infrastructure.

Sign up at snapapi.pics with no credit card required. Generate your first PDF in under five minutes. View the complete API reference including all PDF parameters at snapapi.pics/docs.html.

PDF Generation from Multiple Languages

Since SnapAPI is a REST API, HTML-to-PDF generation works identically from any language that can make HTTP requests.

Go

req, _ := http.NewRequest("GET",
    "https://api.snapapi.pics/v1/pdf?url=https://example.com/invoice&format=A4&print_background=true",
    nil)
req.Header.Set("X-Api-Key", os.Getenv("SNAPAPI_KEY"))
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
io.Copy(os.Stdout, resp.Body) // pipe to file, S3, or HTTP response

PHP

$ch = curl_init("https://api.snapapi.pics/v1/pdf?url=https://example.com/report&format=A4");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-Api-Key: " . $_ENV["SNAPAPI_KEY"]]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$pdf = curl_exec($ch);
file_put_contents("report.pdf", $pdf);

Storing PDFs in S3

For invoice and report workflows, pipe the PDF response directly to S3 rather than writing to local disk. In Node.js, use @aws-sdk/client-s3 with PutObjectCommand and pass the PDF buffer as the body. Generate a pre-signed URL with a 15-minute expiry and email it to the user, or return it in your API response for immediate download.

This serverless pattern — Lambda calls SnapAPI, stores PDF in S3, returns pre-signed URL — requires zero persistent storage and scales to thousands of concurrent PDF generation requests without any infrastructure changes. The entire workflow runs in under 5 seconds for most document templates.

Advanced PDF Options

Beyond basic URL-to-PDF conversion, SnapAPI supports several advanced PDF parameters for production document workflows. The scale parameter adjusts the rendering scale factor — useful for shrinking dense dashboards to fit on a single page. prefer_css_page_size=true respects CSS @page size declarations from your template, letting your design control paper dimensions rather than the API call. tagged_pdf=true produces an accessible PDF with semantic tags, required for regulatory compliance in certain industries.

For authenticated pages — invoices behind a login, dashboard exports requiring a session — use the cookies parameter to pass session cookies from your application. This lets SnapAPI render the authenticated version of the page as if logged in as your user. Combine with a short-lived session token that expires after the PDF is generated for security.

The inject_css parameter is useful for adding @media print overrides on the fly: hide navigation bars, adjust font sizes for print, collapse sidebars, and remove interactive elements. This gives you print-optimized output from pages originally designed for browser display, without maintaining a separate print stylesheet in your codebase.

html to pdf api node python go php pdf generation from url html pdf converter api service serverless
pdf generation api html to pdf convert webpage to pdf wkhtmltopdf alternative puppeteer alternative pdf api service
generate pdf from html url api endpoint
html pdf api