printpipe.io
← All guides

How to make PDF reports with charts

A monthly report with figures, a bar chart and a table, from your data. Charts drawn with plain HTML, or with a chart library such as Chart.js.

reportschartstemplates

Reports are numbers your customers want to keep, forward or print: a monthly summary, a statement, a dashboard as of the end of the quarter. This guide builds one from a template: three key figures, a bar chart and a table, all filled from your data.

There are two ways to draw the chart. Both work; the first is simpler and more reliable.

The first page of the PDF this guide makes: how to make pdf reports with charts
The first page of the PDF, made by printpipe.io from the request below.

The request

Save the template once (Use this template opens it in your dashboard), then send its id and your data for each document:

curl https://api.printpipe.io/v1/generate \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "templateId": "YOUR_TEMPLATE_ID",
  "data": {
    "title": "Sales report",
    "period": "January – June 2026",
    "accent": "#c4472f",
    "kpis": [
      {
        "label": "Revenue",
        "value": "€184,200",
        "change": "▲ 12 % on last half-year"
      },
      { "label": "Orders", "value": "2,481", "change": "▲ 8 %" },
      { "label": "Average order", "value": "€74.25", "change": "▲ 4 %" }
    ],
    "months": [
      { "name": "Jan", "value": "€24.1k", "orders": 342, "percent": 62 },
      { "name": "Feb", "value": "€26.8k", "orders": 371, "percent": 69 },
      { "name": "Mar", "value": "€29.5k", "orders": 398, "percent": 76 },
      { "name": "Apr", "value": "€31.0k", "orders": 412, "percent": 80 },
      { "name": "May", "value": "€34.9k", "orders": 455, "percent": 90 },
      { "name": "Jun", "value": "€37.9k", "orders": 503, "percent": 98 }
    ]
  }
}' \
  --output document.pdf
import { writeFile } from 'node:fs/promises';

const res = await fetch('https://api.printpipe.io/v1/generate', {
  method: 'POST',
  headers: { 'X-API-Key': process.env.API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "templateId": "YOUR_TEMPLATE_ID",
    "data": {
      "title": "Sales report",
      "period": "January – June 2026",
      "accent": "#c4472f",
      "kpis": [
        {
          "label": "Revenue",
          "value": "€184,200",
          "change": "▲ 12 % on last half-year"
        },
        { "label": "Orders", "value": "2,481", "change": "▲ 8 %" },
        { "label": "Average order", "value": "€74.25", "change": "▲ 4 %" }
      ],
      "months": [
        { "name": "Jan", "value": "€24.1k", "orders": 342, "percent": 62 },
        { "name": "Feb", "value": "€26.8k", "orders": 371, "percent": 69 },
        { "name": "Mar", "value": "€29.5k", "orders": 398, "percent": 76 },
        { "name": "Apr", "value": "€31.0k", "orders": 412, "percent": 80 },
        { "name": "May", "value": "€34.9k", "orders": 455, "percent": 90 },
        { "name": "Jun", "value": "€37.9k", "orders": 503, "percent": 98 }
      ]
    }
  }),
});
if (!res.ok) throw new Error((await res.json()).message);
await writeFile('document.pdf', Buffer.from(await res.arrayBuffer()));
import os, requests

res = requests.post(
    "https://api.printpipe.io/v1/generate",
    headers={"X-API-Key": os.environ["API_KEY"]},
    json={
      "templateId": "YOUR_TEMPLATE_ID",
      "data": {
        "title": "Sales report",
        "period": "January – June 2026",
        "accent": "#c4472f",
        "kpis": [
          {
            "label": "Revenue",
            "value": "€184,200",
            "change": "▲ 12 % on last half-year"
          },
          { "label": "Orders", "value": "2,481", "change": "▲ 8 %" },
          { "label": "Average order", "value": "€74.25", "change": "▲ 4 %" }
        ],
        "months": [
          { "name": "Jan", "value": "€24.1k", "orders": 342, "percent": 62 },
          { "name": "Feb", "value": "€26.8k", "orders": 371, "percent": 69 },
          { "name": "Mar", "value": "€29.5k", "orders": 398, "percent": 76 },
          { "name": "Apr", "value": "€31.0k", "orders": 412, "percent": 80 },
          { "name": "May", "value": "€34.9k", "orders": 455, "percent": 90 },
          { "name": "Jun", "value": "€37.9k", "orders": 503, "percent": 98 }
        ]
      }
    },
    timeout=60,
)
res.raise_for_status()
with open("document.pdf", "wb") as f:
    f.write(res.content)

Charts from plain HTML

The template’s chart is a row of div elements whose heights come from your data. No JavaScript is involved, so it looks the same in the editor’s live preview, in the PDF and in every PDF viewer, and it renders fast.

<div class="chart">
  {{#months}}
  <div class="bar"><b>{{value}}</b><span style="height: {{percent}}%"></span></div>
  {{/months}}
</div>

Templates contain no code, so your data carries the numbers ready to draw:

"months": [
  { "name": "Jan", "value": "€24.1k", "orders": 342, "percent": 62 },
  { "name": "Feb", "value": "€26.8k", "orders": 371, "percent": 69 }
]

Work out percent in your code: each month’s value divided by the largest one. Formatting stays in your code too: "€24.1k", not 24100.

The same idea covers progress bars, stacked bars and simple line charts drawn as inline SVG (<polyline points="{{points}}"> with the points from your data).

Charts from a chart library

If your charts already exist in a library like Chart.js, ECharts or Highcharts, use them as they are. The page is rendered in a real browser, so scripts run. Three things make them come out right:

  1. Turn off animations. Otherwise the PDF may catch the chart halfway through growing.
  2. Draw at a higher pixel density, so the chart is sharp when the PDF is zoomed or printed.
  3. Give the script a moment with waitFor, in seconds.
<canvas id="revenue" width="700" height="280"></canvas>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"></script>
<script>
  new Chart(document.getElementById('revenue'), {
    type: 'bar',
    data: { labels: {{{labelsJson}}}, datasets: [{ data: {{{valuesJson}}}, backgroundColor: '#c4472f' }] },
    options: { animation: false, responsive: false, devicePixelRatio: 2, plugins: { legend: { display: false } } },
  });
</script>
{
  "templateId": "YOUR_TEMPLATE_ID",
  "data": { "labelsJson": "[\"Jan\",\"Feb\"]", "valuesJson": "[24100,26800]" },
  "waitFor": 1
}

The triple braces {{{labelsJson}}} print the value as it is, unescaped, which is what a script needs. Use them only for data you made yourself, never for text your users typed.

The editor’s live preview doesn’t run scripts; Render exact does, and shows the chart as the PDF will.

Page breaks

Reports grow. Keep the pieces together:

.chart, .kpis { break-inside: avoid; }  /* a chart is never split across pages */
h2 { break-after: avoid; }              /* a heading stays with what follows */
thead { display: table-header-group; }  /* table headings repeat on every page */
.appendix { break-before: page; }       /* start a section on a new page */

Wide tables fit better in landscape: save landscape with the template’s page settings, or send "landscape": true with one request.

Colours

Browsers leave out background colours when they print, unless told otherwise. We keep them (printBackground is on by default), so coloured bars and table stripes come out as designed. The bar colour comes from {{accent}} in the data, so each customer’s report can use their own.

More guides