Charts in PDF Reports
Render charts as PNG and embed them in any PDF library, or use format: "pdf" for direct single-chart PDF output. Every example is complete and runnable.
Approaches
| Approach | Best for | Plan |
|---|---|---|
| Render PNG → embed in PDF library | Multi-chart reports, custom layouts, mixed content | All plans |
Render directly as format: "pdf" | Single-chart stand-alone PDFs | Pro, Agency |
Embed PNG in a PDF library
Render the chart as PNG (all plans) and embed it with pdfkit (Node.js) or ReportLab (Python). Use padding: "pdf" for generous margins, and scale: 2 for crisp output in print-resolution PDFs.
# Render chart to file
curl -s -X POST https://www.chart-output.com/api/v1/render \
-H "Authorization: Bearer pk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
--output chart.png \
-d '{
"type": "bar",
"width": 500, "height": 280,
"format": "png", "scale": 2,
"padding": "pdf",
"data": {
"labels": ["Q1","Q2","Q3","Q4"],
"datasets": [{ "label": "Revenue", "data": [100,150,120,180] }]
}
}'
# Then use your PDF library of choice to embed chart.pngimport fs from 'fs';
import PDFDocument from 'pdfkit';
// Step 1: render chart as PNG
const res = await fetch('https://www.chart-output.com/api/v1/render', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CHART_OUTPUT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: 'bar',
width: 500,
height: 280,
format: 'png',
scale: 2,
padding: 'pdf',
data: {
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [{ label: 'Revenue', data: [100, 150, 120, 180] }],
},
}),
});
const chartPng = Buffer.from(await res.arrayBuffer());
// Step 2: build the PDF
const doc = new PDFDocument({ size: 'A4', margin: 50 });
doc.pipe(fs.createWriteStream('report.pdf'));
doc.fontSize(24).text('Quarterly Report', 50, 50);
doc.moveDown();
doc.image(chartPng, 50, 110, { width: 500 });
doc.moveDown(16);
doc.fontSize(12).text('Revenue grew 80% year-over-year.', 50);
doc.end();import os, json, urllib.request
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
from io import BytesIO
# Step 1: render chart
resp = urllib.request.urlopen(urllib.request.Request(
"https://www.chart-output.com/api/v1/render",
data=json.dumps({
"type": "bar",
"width": 500, "height": 280,
"format": "png", "scale": 2,
"padding": "pdf",
"data": {
"labels": ["Q1", "Q2", "Q3", "Q4"],
"datasets": [{"label": "Revenue", "data": [100, 150, 120, 180]}],
},
}).encode(),
headers={
"Authorization": f"Bearer {os.environ['CHART_OUTPUT_API_KEY']}",
"Content-Type": "application/json",
},
method="POST",
))
chart_png = BytesIO(resp.read())
# Step 2: embed in PDF
c = canvas.Canvas("report.pdf", pagesize=A4)
width, height = A4
c.setFont("Helvetica-Bold", 24)
c.drawString(50, height - 80, "Quarterly Report")
c.drawImage(chart_png, 50, height - 380, width=500, height=280)
c.setFont("Helvetica", 12)
c.drawString(50, height - 410, "Revenue grew 80% year-over-year.")
c.save()PDF output format (Pro and Agency plans)
Set format: "pdf" to receive a single-page PDF sized to the chart dimensions. Works with card compositions — ideal for branded, printable one-pagers.
curl -s -X POST https://www.chart-output.com/api/v1/render \
-H "Authorization: Bearer pk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
--output chart.pdf \
-d '{
"type": "line",
"width": 800, "height": 500,
"format": "pdf",
"brandKitId": "linen",
"padding": "pdf",
"header": {
"eyebrow": "ANNUAL REPORT 2025",
"title": "Revenue Trend"
},
"data": {
"labels": ["Jan","Feb","Mar","Apr","May","Jun"],
"datasets": [{ "label": "Revenue", "data": [14200,17800,20100,22900,25720,29840] }]
}
}'// Render as PDF directly (Pro or Agency plan required)
const res = await fetch('https://www.chart-output.com/api/v1/render', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CHART_OUTPUT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: 'line',
width: 800,
height: 500,
format: 'pdf',
brandKitId: 'linen',
padding: 'pdf',
header: {
eyebrow: 'ANNUAL REPORT 2025',
title: 'Revenue Trend',
subtitle: 'All figures in USD',
},
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [{ label: 'Revenue', data: [14200, 17800, 20100, 22900, 25720, 29840] }],
},
footer: { left: 'Confidential', right: 'Page 1', borderTop: true },
}),
});
if (!res.ok) throw new Error(await res.text());
const pdfBuffer = Buffer.from(await res.arrayBuffer());
await fs.promises.writeFile('chart.pdf', pdfBuffer);import os, json, urllib.request
resp = urllib.request.urlopen(urllib.request.Request(
"https://www.chart-output.com/api/v1/render",
data=json.dumps({
"type": "line", "width": 800, "height": 500,
"format": "pdf", "brandKitId": "linen", "padding": "pdf",
"header": {"eyebrow": "ANNUAL REPORT 2025", "title": "Revenue Trend"},
"data": {
"labels": ["Jan","Feb","Mar","Apr","May","Jun"],
"datasets": [{"label": "Revenue", "data": [14200,17800,20100,22900,25720,29840]}],
},
}).encode(),
headers={
"Authorization": f"Bearer {os.environ['CHART_OUTPUT_API_KEY']}",
"Content-Type": "application/json",
},
method="POST",
))
open("chart.pdf", "wb").write(resp.read())Requesting PDF on Free returns a 403 with an "plan_required" body that names the plan you need.
Multi-chart report
Render multiple charts in parallel using Promise.all, then compose them on multiple PDF pages:
import PDFDocument from 'pdfkit';
async function renderChart(spec) {
const res = await fetch('https://www.chart-output.com/api/v1/render', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CHART_OUTPUT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ ...spec, format: 'png', scale: 2 }),
});
return Buffer.from(await res.arrayBuffer());
}
const [revenueChart, growthChart] = await Promise.all([
renderChart({
type: 'bar', width: 500, height: 240, padding: 'pdf',
data: { labels: ['Q1','Q2','Q3','Q4'], datasets: [{ label: 'Revenue', data: [100,150,120,180] }] },
}),
renderChart({
type: 'line', width: 500, height: 240, padding: 'pdf',
data: { labels: ['Q1','Q2','Q3','Q4'], datasets: [{ label: 'Growth %', data: [12,18,14,22] }] },
}),
]);
const doc = new PDFDocument({ size: 'A4', margin: 50 });
doc.pipe(fs.createWriteStream('report.pdf'));
doc.fontSize(20).text('Annual Report', 50, 50);
doc.image(revenueChart, 50, 100, { width: 500 });
doc.addPage();
doc.image(growthChart, 50, 100, { width: 500 });
doc.end();Related walkthroughs
Chart.js PDF reports
Build automated PDF reports with chart visuals, without launching a headless browser.
Convert Chart.js to an image
Export a Chart.js config as PNG, SVG, WebP or PDF for email, reports and pipelines.
chartjs-node-canvas vs Puppeteer
The two DIY ways to render Chart.js on a server, compared, and when neither is worth building.