PDF report generation

Generate PDF Reports from HTML and Dashboards

Turn server-rendered report HTML into paginated PDFs with charts, landscape layouts, print styles, and repeatable delivery.

Updated

Key outcomes

Create a document-specific report view

A good PDF report is usually a dedicated HTML view, not a blind capture of the dashboard. Remove interactive filters, expand truncated labels, include the selected date range, and render a clear empty state when there is no data.

Generate this view on the server when the report contains private data. Serialize the finished markup as source so the PDF request does not need access to your application session.

Prepare charts and tables for pagination

Use fixed chart dimensions and wait until their rendering library has produced SVG or canvas output. For long tables, repeat header rows and keep summary blocks together with print CSS.

  • Use break-inside: avoid for charts and KPI cards.
  • Use thead { display: table-header-group } for repeated table headers.
  • Switch to landscape for wide comparison tables.
  • Add a generated-at timestamp and the report filters to the visible document.

Generate a landscape report

This request uses print styles, landscape A4, a short chart delay, and a footer with page numbers.

generate-report.jsJavaScript
const response = await fetch('https://api.pixeltopdf.com/convert/pdf', {
  method: 'POST',
  headers: {
    'X-API-Key': process.env.PIXELTOPDF_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    source: reportHtml,
    format: 'A4',
    landscape: true,
    use_print: true,
    delay: 500,
    margin: { top: '15mm', right: '12mm', bottom: '20mm', left: '12mm' },
    footer: {
      height: '10mm',
      source: '<div style="font-size:9px;width:100%;text-align:right;padding-right:12mm">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>',
    },
  }),
});

if (!response.ok) throw new Error(`Report failed: ${response.status}`);
const reportPdf = Buffer.from(await response.arrayBuffer());

Own the scheduling and delivery workflow

PixelToPdf generates the file synchronously. Your application decides when a report runs and where the bytes go. For scheduled reports, enqueue one job per recipient or account, apply bounded retries, and record the report period with the output.

Do not retry validation or authentication errors blindly. Retry only transient failures, and make the job idempotent so users do not receive duplicate emails or files.

Frequently asked questions

Can I generate charts in a PDF report?

Yes. Render the charts into your HTML and use a short delay when the chart library needs time after page load. Test the chosen SVG or canvas library in Chromium.

Should reports use portrait or landscape?

Portrait works well for narrative reports. Landscape is useful for wide tables and side-by-side charts. Set landscape explicitly so output is predictable.

How do I schedule report generation?

Use your existing queue or scheduler to build the HTML, call PixelToPdf, and deliver or store the returned PDF bytes.

Continue building

Build your first conversion

Start with 75 free credits each month. No credit card required.