Liuska CLI
liuska is one static binary. It needs no browser, no runtime and no system fonts.
liuska render -t template.json [-d data.json|data.csv|-] [-o out.pdf|-] [--strict] [--png --page N --dpi 96]
liuska validate template.json [-d data.json] [--json]
liuska batch -t template.json -d records.ndjson|records.json -o outdir/ [--name "{{id}}.pdf"] [-j N]
liuska serve [--addr 127.0.0.1:8080] [--templates dir] [--editor-dir editor-web/dist]
liuska version
Run liuska <command> -h for the flags of a command.
render
Renders one document.
liuska render -t examples/invoice/template.json -d examples/invoice/data.json -o invoice.pdf
| Flag | Description |
|---|---|
-t |
Template file. Relative paths inside it (images, fonts, snippets, sampleDataFile) are resolved from the template's directory. |
-d |
Data file: .json or .csv, or - for stdin. Without it, the template's sampleData / sampleDataFile is used. |
--data-format |
json or csv. Needed with -d -, or when the extension doesn't say. |
--csv-key |
Key the CSV rows are stored under (default rows). |
-o |
Output file, or - for stdout. |
--strict |
Treat missing bindings as errors (exit 1) instead of empty strings. |
--png |
Render one page as PNG instead of a PDF. |
--page N |
Page for --png (1-based, default 1). |
--dpi |
Resolution for --png (default 96). |
--sign-p12, --sign-key + --sign-cert, --sign-password |
Sign the PDF (PAdES B-B) with a PKCS#12 file or PEM key + chain. |
--sign-field, --sign-reason, --sign-location, --sign-contact, --sign-name, --tsa-url |
Signature placement, details and an optional RFC 3161 timestamp. |
--encrypt, --user-password, --owner-password, --permissions |
AES-256 encryption. |
The signing and encryption flags are also accepted by batch and serve; see forms-and-signing.md.
Password values take env:NAME or file:PATH.
Pipes work both ways:
curl -s https://internal/api/report/42 | liuska render -t report.json -d - -o - > report.pdf
liuska render -t report.json -d data.json --png --page 2 --dpi 150 -o page2.png
validate
Checks a template statically (schema, unknown styles, duplicate or dangling anchor ids, bad formats, column definitions). With -d, it also checks the template against data: missing binding paths, a data path that is not an array, wrong types for formats.
liuska validate examples/sales-report/template.json -d examples/sales-report/data.json
liuska validate template.json --json # machine-readable
Text output has one issue per line, with a severity and a path into the template:
error elements[3].columns[1].format: unknown filter "curency"
warning elements[5].content: binding "customer.vat" not found in data
--json prints the issues as a JSON array:
[{ "path": "elements[3].columns[1].format", "message": "unknown filter \"curency\"", "severity": "error" }]
The exit code is 3 if any issue has severity error. Warnings alone exit 0.
batch
Renders one PDF per record, the way you would for a run of invoices or payslips.
liuska batch -t examples/invoice/template.json -d invoices.ndjson -o out/ --name "{{invoice.number}}.pdf" -j 8
| Flag | Description |
|---|---|
-d |
Records: NDJSON (one JSON object per line) or a JSON array |
-o |
Output directory (created if missing) |
--name |
File name template using the same bindings as text elements (default: the record's index, e.g. 0001.pdf) |
-j |
Parallel workers (default: number of CPUs). One engine is shared, so fonts are loaded once. |
The template is parsed once and reused for every record.
serve
Starts the HTTP API and the designer.
liuska serve # http://127.0.0.1:8080
LIUSKA_API_KEYS=$(cat keys) liuska serve --addr 0.0.0.0:9000 --templates ./templates --read-only
| Flag | Description |
|---|---|
--addr |
Listen address (default 127.0.0.1:8080). Binding to a non-loopback address requires API keys or --no-auth. |
--templates |
Directory of *.json templates. They can be rendered by name (templateName) and opened and saved from the designer. |
--editor-dir |
Serve the designer from this directory instead of the build embedded in the binary. Useful while developing editor-web/. |
--api-key-file, --api-key |
Require API keys (also LIUSKA_API_KEYS). Needed to listen on a non-loopback address unless --no-auth is set. |
--read-only |
Reject template writes. |
--cors-origin, --allowed-host |
Browser origins allowed to call the API (CORS is off by default), and accepted Host headers. |
--asset-dir |
Extra directory templates may read files from. Otherwise only the templates directory is allowed. |
--max-body, --timeout, --max-concurrent, --max-pages, --max-rows |
Request and render limits (defaults: 32MB, 30s, 2 x CPUs, 5000, 200000). |
See http-api.md for the endpoints, security.md for hardening and designer.md for the editor.
version
liuska version
Data formats
JSON
Any JSON value. Templates usually expect an object ({ "customer": {...}, "items": [...] }). Bindings address it with dot/index paths.
CSV
.csv files (or --data-format csv) are turned into an object with one key holding the rows:
Region,Product,Jan,Feb
Uusimaa,Desk 120,8773.18,9137.71
becomes
{ "rows": [ { "Region": "Uusimaa", "Product": "Desk 120", "Jan": 8773.18, "Feb": 9137.71 } ] }
- The first line is the header and becomes the object keys, in column order (so
autoColumnskeeps the CSV order). - Values that look like numbers become numbers; everything else stays a string.
--csv-key itemsstores the rows underitemsinstead ofrows.- Bind a table with
"data": "rows".
NDJSON (batch)
One JSON object per line. A JSON array of objects also works.
Exit codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Render error (I/O, bad data, missing font/image, --strict binding failure) |
| 2 | Usage error (unknown flag or missing argument) |
| 3 | Validation failed (validate found at least one error, or render refused an invalid template) |
Errors go to stderr, and the output (-o -) goes to stdout, so piping is safe.
Tips for speed
- Use
serveorbatchfor volume. They keep one warm engine: fonts are parsed once and templates are cached. A coldrenderstill has to start the process, which takes under 100 ms for a one-page document. - Large tables are fine. A 10,000-row table renders in under a second, and memory grows roughly linearly.
- Only the glyphs a document uses are embedded, so custom fonts don't bloat the PDF.