Receipt

A compact point-of-sale style receipt with itemised lines, totals, and tax breakdown.

  • POS
  • Compact
  • Thermal
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 { readFile, writeFile } from 'node:fs/promises';
import Handlebars from 'handlebars';

// Download the template from https://html2pdf.app/template-files/receipt.hbs
// and keep a copy next to your code, so our updates never change your PDFs.
const templateSource = await readFile('./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 fetch('https://api.html2pdf.app/v1/generate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': process.env.HTML2PDF_API_KEY,
  },
  body: JSON.stringify({ html }),
});

if (!response.ok) {
  throw new Error('PDF generation failed with status ' + response.status);
}

const pdf = Buffer.from(await response.arrayBuffer());
await writeFile('./receipt.pdf', pdf);