HTML invoice to PDF with one API call
Turn an HTML invoice or receipt into a PDF with curl: page size, orientation and margins, multi-page tables, fonts and images.
You already have the invoice as HTML, from a template, a script or an AI agent. This guide sends it to DocGen and saves the PDF, with no browser to install or run.
Before you start
Sign in, create an API key in the dashboard and export it as DOCGEN_API_KEY. The examples also use jq to build the JSON body. The free plan gives you 50 conversions a month on the Tiger engine, which is made for invoices and receipts.
export DOCGEN_API_KEY=dk_live_...
1. Write the invoice
Plain HTML and CSS. Put the CSS in a <style> block, or send it separately in the css field; Tiger ignores <link> stylesheets. Save this as invoice.html:
<style>
@page {
size: A4;
margin: 18mm 16mm;
@bottom-center { content: "Page " counter(page) " of " counter(pages); font-size: 8pt; }
}
body { font-size: 10pt; color: #1c2530; }
table { width: 100%; border-collapse: collapse; }
thead { display: table-header-group; }
th, td { padding: 5pt; border-bottom: 0.5pt solid #d4dae1; text-align: left; }
.num { text-align: right; }
</style>
<h1>Invoice INV-2026-0918</h1>
<p>Bill to: Acme Logistics GmbH · Due 8 November 2026</p>
<table>
<thead><tr><th>Item</th><th class="num">Qty</th><th class="num">Amount</th></tr></thead>
<tbody>
<tr><td>Hosting, October</td><td class="num">1</td><td class="num">€1,200.00</td></tr>
<tr><td>Support hours</td><td class="num">6</td><td class="num">€540.00</td></tr>
</tbody>
</table>
<p class="num"><strong>Total €1,740.00</strong></p>2. Send it
POST the HTML to /api/v1/pdf as JSON. jq reads the file and escapes quotes and newlines for you. The optional title becomes the PDF document title. The response body is the PDF itself.
jq -n --rawfile html invoice.html '{html: $html, title: "INV-2026-0918"}' |
curl -sS --fail-with-body -X POST "https://docgen.novtopro.com/api/v1/pdf" \
-H "Authorization: Bearer $DOCGEN_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- -o invoice.pdfA successful call returns 200 with application/pdf. Any other status comes with a JSON body naming the error code, such as quota_exceeded; --fail-with-body makes curl exit non-zero, so a script won't mistake the error for a PDF.
3. Page size, orientation and margins
On Tiger, three optional fields set the page layout and override CSS @page: pageSize (letter, a4, legal or tabloid; default letter), orientation (portrait or landscape) and margins in points, 1/72 of an inch: one number for every side, or an object with top, right, bottom and left. The default margin is 40 points.
{
"html": "<h1>Invoice INV-2026-0918</h1>…",
"pageSize": "a4",
"orientation": "landscape",
"margins": { "top": 36, "right": 28, "bottom": 36, "left": 28 }
}Lion and Wolf ignore these three fields. On those engines, set the page in CSS:
@page { size: A4 landscape; margin: 12mm 10mm; }4. Multi-page invoices
Keep line items in one table with a <thead>: when the table runs past a page, the header row repeats at the top of the next one. Page numbers come from counter(page) and counter(pages) in an @page margin box, as in the example above. Tiger can't force page breaks; for break-before, break-after and break-inside, use Lion or Wolf.
5. Fonts and images
Tiger sets text in Helvetica, switching to Noto Sans JP when the text has characters beyond Latin-1; font-family and @font-face are ignored. Images must be PNG or JPEG, from a data: URI or a public http(s) URL, up to 5 MB each with no redirects. For a logo, a small base64 data: URI is the most reliable choice.
Need your own fonts, SVG logos, or long documents in Chinese or Japanese? On Pro, send engine lion or wolf: both load TTF and OTF fonts via @font-face and SVG images, and Wolf also takes WOFF and WOFF2.
jq -n --rawfile html invoice.html '{html: $html, engine: "lion"}' |
curl -sS --fail-with-body -X POST "https://docgen.novtopro.com/api/v1/pdf" \
-H "Authorization: Bearer $DOCGEN_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- -o invoice.pdfLimits to know
- No JavaScript runs. Compute totals and render charts to images before you send the HTML.
- The request body is capped per plan: 256 KB on Free, 4 MB on Pro. Embedded images count, so link large ones by URL.
- Free allows 5 requests a minute. Past that you get 429 with a Retry-After header saying how many seconds to wait.
- Nothing is stored. The HTML and the PDF exist only for the request, so keep your own copy of every invoice.