Shipping Label

A 4×6 shipping label with sender, recipient, tracking code, and carrier zone.

  • 4×6
  • Barcode
  • Thermal
How to use
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/shipping-label.hbs', 'utf8');
const template = Handlebars.compile(templateSource);

const params = {
  service: 'PRIORITY',
  deliverySpeed: '2-DAY',
  zone: 'Z5',
  sender: {
    name: 'Acme Fulfillment',
    addressLine1: '100 Warehouse Road',
    addressLine2: 'Austin, TX 78701',
  },
  recipient: {
    name: 'Jamie Rivera',
    addressLine1: '455 Pine Street Apt 8',
    addressLine2: 'Seattle, WA 98101',
  },
  trackingNumber: '9400 1000 0000 0000 8842 19',
};

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('./shipping-label.pdf', response.data);