Invoices, receipts and reports
Recipes for HTML invoices to A4 or Letter PDFs, 80 mm receipts, page numbers, repeated table headers and storing the result.
A4 invoice with page numbers#
{
"html": "<!doctype html><html>...your invoice...</html>",
"format": "A4",
"margin": { "top": "18mm", "bottom": "20mm", "left": "14mm", "right": "14mm" },
"footer_template": "<div style='font-size:9px;width:100%;text-align:center;color:#555'>Invoice 1042, page <span class='pageNumber'></span> of <span class='totalPages'></span></div>"
}
Use "format": "Letter" for US customers.
80 mm receipt#
{ "html": "...", "width": "80mm", "height": "200mm", "margin": "3mm" }
CSS that keeps long documents tidy#
@media print {
thead { display: table-header-group; } /* repeat table headers on every page */
tr, .totals { break-inside: avoid; } /* never split a row or the totals */
.terms { break-before: page; } /* start a section on a new page */
}
Fonts and alphabets#
Turkish, Arabic, Hebrew, Chinese, Japanese, Korean, Thai and Devanagari text and color emoji render out of the box. For your brand font, link it in the HTML; web fonts are loaded before printing. On slow font hosts add "wait_until": "networkidle".
Store the file#
Render once when the invoice is final and save the PDF in your own storage. If another service needs a link, use "response_type": "url": the link works for 24 hours.
r = requests.post(
"https://rendersbolt.com/v1/pdf",
headers={"Authorization": f"Bearer {os.environ['API_KEY']}"},
json={"html": invoice_html, "format": "A4", "margin": "15mm"},
)
r.raise_for_status()
storage.put(f"invoices/{invoice.id}.pdf", r.content)
const pdf = Buffer.from(await res.arrayBuffer());
await storage.put(`invoices/${invoice.id}.pdf`, pdf);
Read the longer guide on the blog: How to turn an HTML invoice into a PDF with one API call.
Stuck? Write to [email protected] with the request you sent and the error code you got back.