Report

A multi-page analytics report layout with title page, summary, and chart placeholders.

  • Analytics
  • Multi-page
  • A4
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/report.hbs', 'utf8');
const template = Handlebars.compile(templateSource);

const params = {
  reportTitle: 'Monthly Performance Report',
  period: 'June 2026 summary',
  companyName: 'Acme Analytics',
  kpis: [
    { label: 'Revenue', value: '$184k' },
    { label: 'Conversion', value: '6.8%' },
  ],
  revenueTrend: [{ height: '44%' }, { height: '58%' }, { height: '72%' }],
  channels: [
    {
      name: 'Organic search',
      sessions: '42,880',
      conversion: '7.2%',
      revenue: '$74,300',
    },
  ],
  recommendation: 'Expand lifecycle email campaigns.',
};

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