How it works

Template + data → PDF

A template describes the layout: page size, bands, text, tables and charts, with {{bindings}} to your data. Your backend sends the data it already has. Liuska does the layout and pagination and writes the PDF. There is no HTML step in between.

Write a template

This is the hello.json from the quick start, unedited: a heading bound to name, a table whose columns come from the rows (autoColumns) with a totals row, and a page-number footer.

Templates are plain JSON, so they live in git next to your code. Add "$schema" to get validation and hover docs in VS Code. You can also build them in the designer, which saves the same format.

Positions are in points (1/72 in). Units such as "10mm" and "100%" work too.

hello.json

{
  "version": 1,
  "page": { "size": "A4", "margins": { "top": 40, "right": 40, "bottom": 40, "left": 40 } },
  "footer": { "height": 20, "elements": [
    { "type": "text", "align": "right", "content": "Page {{page}} of {{pages}}",
      "x": 315, "y": 4, "width": 200, "height": 12 } ] },
  "elements": [
    { "type": "text", "fontSize": 20, "bold": true, "content": "Hello {{name}}",
      "x": 40, "y": 40, "width": 515, "height": 26 },
    { "type": "table", "id": "t", "x": 40, "y": 80, "width": "100%",
      "data": "rows", "autoColumns": true,
      "headerStyle": { "bold": true, "fill": "#f0f0f0" },
      "totals": { "item": "Total", "price": "sum" } }
  ]
}

Send your data

JSON from your backend, or a CSV file. A CSV becomes { "rows": [...] } and numbers are detected. Bindings use dotted paths ({{customer.name}}) and filters ({{ total | currency:"EUR" }}). The template's locale sets separators and month names.

data.json

{ "name": "world",
  "rows": [ { "item": "Coffee", "price": 3.5 },
            { "item": "Bun",    "price": 2.9 } ] }

Render it

From the CLI, in a script or a CI job. - means stdin or stdout. Exit codes: 0 ok, 1 render error, 2 usage, 3 validation failed.

Or run liuska serve and call it over HTTP. The engine stays warm between requests and renders concurrently. The server is stateless, so you can run several instances behind a load balancer.

The result, top of the page, rendered with --png:

Rendered output: the heading 'Hello world' and a table with columns item and price, rows Coffee 3.5 and Bun 2.9, and a bold Total row of 6.4.
Output of the commands on this page (cropped; the footer reads "Page 1 of 1").

CLI

# one document
liuska render -t hello.json -d data.json -o hello.pdf

# data from stdin, PDF to stdout
cat data.json | liuska render -t hello.json -d - -o - > hello.pdf

# PNG preview of page 1
liuska render -t hello.json -d data.json --png --page 1 --dpi 110 -o hello.png

# check bindings and formats without rendering (exit 3 on errors)
liuska validate hello.json -d data.json

# one PDF per record, 8 in parallel
liuska batch -t invoice.json -d records.ndjson -o out/ --name "{{id}}.pdf" -j 8

HTTP API

liuska serve --addr 127.0.0.1:8080 --templates ./templates

curl -X POST http://127.0.0.1:8080/api/render \
  -H "Content-Type: application/json" \
  -d '{"templateName":"invoice","data":{"customer":{"name":"Acme"}}}' \
  -o invoice.pdf
# response headers: X-Liuska-Pages, X-Liuska-Duration-Ms
# also: /api/preview (PNG), /api/validate, /api/templates, /api/healthz

What happens inside

All of this is Go code in one process. There is no browser and no external renderer.

  1. Parse & validateVersioned template, checked against the schema. Bindings are checked against the data.
  2. BindPaths, filters and locale formatting. visibleIf hides elements.
  3. Lay outTables flow onto new pages and anchors follow them. Repeated elements reserve their space.
  4. WriteIts own PDF 1.7 writer with font subsetting. Charts are written as vectors.
  5. PreviewThe same layout rasterised to PNG for the designer and --png.

A real report

examples/sales-report is a six-page monthly sales report. The month columns come from the data (columnsFrom) and the KPI strip repeats on every page. It has a combo chart with a secondary axis, Finnish number formatting, and a donut chart anchored under the table on the last page.

liuska render -t examples/sales-report/template.json \
  -d examples/sales-report/data.json -o sales.pdf

Walk-through: converting this report from wkhtmltopdf

Page 1 of the sales report: header with logo and title, KPI strip, combo chart and bar chart, and the start of the sales table.
Page 1 of 6, rendered with --png --dpi 110.