Skip to content

Generate a PDF report with charts from data ​

What you get: A two-page A4 PDF with three charts (a bar chart, a donut and an ageing histogram), built from data in the workflow.

Needs: No API key; Playwright Chromium for the PDF · Time: 10 minutes · Nodes: 7

A Set node holds three small data sets: key counts by cloud, by algorithm and by age. Three Chart nodes turn them into SVG from Vega-Lite specs, on the server, with no browser. A Prompt Template places the SVGs in an HTML page, and PDF Output prints that page to A4 with headless Chromium. No model is involved, so it runs without a key. Swap the Set node for real data, such as an HTTP request, a database query or an MCP tool, and the rest stays the same.

Steps ​

  1. Download report-with-charts-flow.json, or take it from the samples folder on GitHub.
  2. In the studio's workflow editor, import the file (see import and export).
  3. Install Chromium for Playwright on the API host once: pnpm exec playwright install chromium from the repo root. Or point PDF_CHROMIUM_EXECUTABLE_PATH at a Chromium you already have.
  4. Run it. Open the run and click PDF: the node output has the file as pdf.downloadUrl (a data:application/pdf;base64,... URL) and pdf.base64. The Output node returns that URL as result.
  5. Save the PDF from the URL, or run the workflow from the studio's chat, which shows a Download PDF link when the answer is a PDF data URL.

How it works ​

Diagram of the Report with Charts (PDF) workflowRuns Sample Data, then Keys by Cloud, then Keys by Algorithm, then Keys by Age, then HTML Report, then PDF, then Output.Sample Data (set_node)Sample Dataset_nodeKeys by Cloud (chart)Keys by CloudchartKeys by Algorithm (chart)Keys by AlgorithmchartKeys by Age (chart)Keys by AgechartHTML Report (prompt_template)HTML Reportprompt_templatePDF (pdf_output)PDFpdf_outputOutput (output)Outputoutput
Solid arrows are the order the steps run in. Dashed lines attach a chat model, memory, tools or workers to an agent; the agent uses them while it runs.
NodeTypeRole
Sample Dataset_nodeStep in the run
Keys by CloudchartStep in the run
Keys by AlgorithmchartStep in the run
Keys by AgechartStep in the run
HTML Reportprompt_templateStep in the run
PDFpdf_outputStep in the run
OutputoutputStep in the run

5 node types. Each type links to its config fields in the node reference.

What a run does ​

On our install the whole run took about 1.2 seconds. The three charts took 10 to 30 ms each, and the PDF step about 1.1 seconds, most of it starting Chromium. The PDF was 34,859 bytes, two A4 pages titled Key Inventory Report: the cloud bar chart and the algorithm donut on page 1, and the age histogram on page 2, below a heading left at the foot of page 1. Add h2{break-after:avoid}.chart{break-inside:avoid} to the template's CSS to keep each heading with its chart.

The file name came out as key-report-.pdf: its template is key-report-{{session_id}}.pdf and a run without a session has an empty session_id. Pass a session_id, or use another value in the name.

Without Chromium. We pointed PDF_CHROMIUM_EXECUTABLE_PATH at a missing file. The three charts and the HTML still rendered, then the PDF node failed with browserType.launch: Failed to launch chromium because executable doesn't exist at ... and the run ended with an error. Chart rendering never needs the browser; only the HTML-to-PDF step does.

The chart specs ​

Each Chart node holds a Vega-Lite spec without data. Vega-Lite describes a chart as a mark (bar, arc, line...) and an encoding that maps data fields to channels such as x, y, theta and color. The node's dataPath (byCloud, byAlgorithm, ageing) points at rows from the earlier node and fills in the data. The Set node's values are JSON strings, and the run turned them into arrays of rows.

The age chart sets "sort": null on its x axis so the buckets keep their order (<30d, 30-90d and so on) instead of sorting by name. width and height on the node are defaults; a size in the spec wins. Each chart's outputKey (cloudChart and so on) holds svg and a dataUrl. The node also puts svg, dataUrl and a ready imgTag at the top level, but three charts feed one template here and those top-level keys overwrite each other, so the template uses {{cloudChart.svg}} to inline each SVG. See the Chart node for every field, and use specTemplate when the spec itself depends on the data.

HTML template and PDF output ​

The HTML Report node is a Prompt Template used as an HTML template: a full page with inline CSS and the three SVGs. Nothing in it calls a model. PDF Output in html render mode reads the html key, loads it in Chromium, waits for the network to go quiet (up to 45 seconds) and prints with printBackground on and the A4 page size (Letter, Legal, A3 and A5 also work).

Anything the HTML loads from the web, such as a font or an image URL, goes through the outbound URL checks. The inline SVGs load nothing. PDF Output also has a text mode that writes plain text into a PDF without a browser, but it cannot show charts.

Add an LLM summary (optional) ​

To open the report with a written summary, add a Prompt Template after Sample Data that asks for a short summary of the rows (for example with {{byCloud}} and {{ageing}}), then an LLM Call, and connect the LLM Call to HTML Report next to the charts. Then put its answer into the template as {{answer}}. The model only writes text; the numbers in the charts still come from the data.

Make it yours ​

  • Replace Sample Data with real data: an HTTP Request, a database connector or an MCP tool, as long as the rows reach the charts under the names in dataPath.
  • Brand it: change the colors in the specs (mark.color, scale.scheme), or pass a Vega theme object on each Chart node so every chart shares one style. The brand extraction recipe finds a site's logo and colors.
  • Run it on a schedule with a Schedule Trigger and send the PDF on with an email or storage node.

Make it safer ​

These controls are optional; the recipe runs without them.

  • If any HTML comes from user input or a model, turn on OUTBOUND_DENY_PRIVATE (off by default) so the page cannot load internal URLs: see outbound URL checks.
  • The PDF travels as base64 inside the run result and is stored with the run, so anyone who can read the run can read the report.

Further reading ​

This website (not the L2M product) uses Google Analytics, only after you accept cookies. Cookie settings