Receipt
A compact point-of-sale style receipt with itemised lines, totals, and tax breakdown.
How to use
Render the template, then convert it to PDF
Download the prepared Handlebars template, render it with runtime params, and send the final HTML to the html2pdf.app API.
import fs from 'fs';
import axios from 'axios';
import Handlebars from 'handlebars';
const templateSource = fs.readFileSync('./templates/receipt.hbs', 'utf8');
const template = Handlebars.compile(templateSource);
const params = {
store: {
name: 'Acme Market',
addressLine1: '123 Main Street',
addressLine2: 'San Francisco, CA',
},
receiptNumber: 'R-1048',
date: '2026-06-10 14:32',
cashier: 'M. Chen',
items: [
{ name: 'Notebook set', quantity: 2, unitPrice: '$8.50', amount: '$17.00' },
],
subtotal: '$17.00',
tax: '$1.45',
total: '$18.45',
paymentMethod: 'Card',
paymentReference: '**** 4242',
message: 'Thank you for your purchase.',
};
const html = template(params);
const response = await axios.post(
'https://api.html2pdf.app/v1/generate',
{ html },
{
responseType: 'arraybuffer',
headers: {
'X-API-Key': process.env.HTML2PDF_API_KEY,
},
},
);
fs.writeFileSync('./receipt.pdf', response.data);