HTML to PDF by API: invoices rendered by Chrome
Generate invoices, receipts and reports as PDF from HTML with one API call. Page size, margins, page numbers in the footer, web fonts, and waiting for JavaScript.
The easiest way to design a document is the way you design a web page: HTML and CSS. The HTML to PDF API prints that HTML with headless Chromium, so what you see in Chrome's print preview is what you get.
curl https://api.justapi.tech/v1/pdf/from-html \
-H "Authorization: Bearer ak_live_..." \
-H "Content-Type: application/json" \
-d '{"html": "<html><body><h1>Invoice #1042</h1><table>...</table></body></html>", "options": {"format": "Letter", "margin": "15mm", "footer_html": "<div style=\"font-size:9px;width:100%;text-align:center\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>"}}'
Page setup
format:A4,Letter,Legal,A3,A5orTabloid. Orwidthandheightas CSS lengths for custom sizes, like receipts:"width": "80mm", "height": "200mm".margin: one CSS length, or{ "top": "20mm", "bottom": "15mm", "left": "12mm", "right": "12mm" }.landscape,scale(0.1 to 2),print_background(on by default, so colored table rows print).prefer_css_page_size: truelets an@page { size: ... }rule in your CSS win.
Page numbers and headers
header_html and footer_html are small HTML templates drawn on every page. Chromium fills elements with these classes: pageNumber, totalPages, date, title, url. Set a font size in the template; the default is tiny. Leave room with the margin, or the footer overlaps the body.
Fonts and images
Web fonts from Google Fonts or your own CDN load like in a browser. Images must be on public URLs or data URIs. Requests to private addresses (localhost, 10.x, 192.168.x, cloud metadata) are blocked; see why the renderer blocks internal addresses.
JavaScript
Scripts run. By default the page prints when the network has been quiet for a moment (wait_until: "networkidle"). For charts or pages that render after data loads:
wait_for_selector: print once an element exists, like#chart-ready. Add that element at the end of your rendering code.delay_ms: a fixed wait up to 10 seconds, when you cannot add a marker.
Navigation has a 30-second limit, so slow pages fail with a clear error and no charge.
Page breaks
Standard CSS works: break-before: page on a heading, break-inside: avoid on table rows and cards. Repeat a table header on each page with thead { display: table-header-group; }.
Cost
$0.006 per PDF at the first tier, whatever its length. Try your HTML in the free HTML to PDF tool.