A procurement-ready PO template with supplier details, items, and approval block.
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/purchase-order.hbs', 'utf8');
const template = Handlebars.compile(templateSource);
const params = {
buyer: {
name: 'Acme Manufacturing',
address: '88 Industrial Way, Austin, TX',
},
poNumber: 'PO-7741',
issueDate: '2026-06-10',
supplier: {
name: 'Office Supply Co.',
addressLine1: '901 Commerce Ave',
addressLine2: 'Dallas, TX 75201',
},
shipTo: {
name: 'Acme Warehouse B',
addressLine1: 'Dock 4',
addressLine2: 'Austin, TX 78701',
},
items: [
{
sku: 'PRN-220',
description: 'Printer paper, A4, 80gsm',
quantity: 40,
unitPrice: '$6.40',
amount: '$256.00',
},
],
total: '$256.00',
requestedBy: 'Nora Chen',
approvedBy: 'Sam Patel',
};
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('./purchase-order.pdf', response.data);