Command-Line Interface
pdfik is the official command-line client for the PDFik API: render URLs and HTML to
PDF from a terminal, a shell script or a CI job â no code to write. It is a single static
binary for Linux, macOS and Windows (also a few-megabyte container image) and ships a
wkhtmltopdf compatibility mode, so existing scripts keep working with an alias.
Source, issues and the complete reference: github.com/pdfik/cli.
Installation
| Method | How |
|---|---|
| Release binaries | github.com/pdfik/cli/releases â Linux (amd64, arm64), macOS (amd64, arm64), Windows (amd64), with checksums.txt |
| Go 1.23 or newer | go install github.com/pdfik/cli/cmd/pdfik@latest |
| Docker | docker pull ghcr.io/pdfik/cli:latest â linux/amd64 and linux/arm64 |
# Linux: download, verify the checksum, install
curl -LO https://github.com/pdfik/cli/releases/latest/download/pdfik-linux-amd64
curl -LO https://github.com/pdfik/cli/releases/latest/download/checksums.txt
sha256sum --ignore-missing -c checksums.txt
chmod +x pdfik-linux-amd64 && sudo mv pdfik-linux-amd64 /usr/local/bin/pdfik
pdfik version
An API key is required â create one in the dashboard
and export it as PDFIK_API_KEY. Prefer the variable over --api-key: flag values are
visible to other processes and end up in shell history. See Authentication.
Quick Start
export PDFIK_API_KEY=sk_live_YOUR_KEY
pdfik url-to-pdf https://example.com # saves ./<job-id>.pdf
pdfik url-to-pdf https://example.com -o ./pdfs -f example.pdf # -o directory, -f file name
pdfik html-to-pdf invoice.html -f invoice.pdf --format A4 --margin 10mm --margin-top 25mm
pdfik url-to-pdf https://example.com --test # free test run, sample PDF
pdfik url-to-pdf https://example.com -o - > example.pdf # stream the PDF to stdout
pdfik status <job-id>
pdfik download <job-id> -o ./pdfs # fetch a finished job later
One command does the whole job lifecycle: submit, poll until the render finishes
(respecting the API's rate limits and Retry-After), download, and write
the file atomically â a failed download never truncates a PDF from an earlier run. Flags
are validated before anything is submitted, so a wrong format or a margin without a unit
costs nothing.
html-to-pdf input is sanitized by the API (<style>, <script> and class attributes
are stripped, relative assets are not resolved) â see Convert HTML to PDF.
url-to-pdf renders with full fidelity; prefer it for styled documents.
Common Options
| Flag | Meaning | Default |
|---|---|---|
-o, --output DIR | output directory (created if missing); - streams the PDF to stdout | current directory |
-f, --file-name NAME | file name inside the output directory | <job-id>.pdf |
--format SIZE | A0âA6, Letter, Legal, Tabloid, Ledger | A4 |
--landscape | landscape orientation | portrait |
--margin VALUE | all sides, or CSS shorthand top,right,bottom,left; units required (mm, cm, in, px) | renderer default |
--margin-top âĻ --margin-left VALUE | one side; overrides --margin for that side | renderer default |
--no-background | skip CSS backgrounds | backgrounds print |
--test | free test run: full pipeline, sample PDF, no quota used | off |
--timeout DUR | how long to wait for the render (90s, 3m) | 3m |
-q, --quiet | no progress lines; warnings and errors still print | off |
The full flag reference, including --api-url and the environment variables, is in the
README.
Docker
docker run --rm --user "$(id -u):$(id -g)" -e PDFIK_API_KEY \
-v "$PWD:/work" -w /work ghcr.io/pdfik/cli url-to-pdf https://example.com -f example.pdf
--user keeps the output file owned by you (the image runs as an unprivileged user);
-o - streams to stdout and sidesteps file ownership entirely.
E-invoicing (Factur-X)
pdfik einvoice-to-pdf takes a UN/CEFACT Cross-Industry Invoice XML file (the Factur-X payload, UTF-8, up to 1 MB; - reads it from stdin) and writes a Factur-X / ZUGFeRD hybrid e-invoice: a PDF/A-3 file with the XML embedded as factur-x.xml. It runs the same submit â poll â download â atomic-write lifecycle as the other commands and uses the same exit codes. Available on every plan, Free included â the output is the same clean PDF/A-3. Endpoint reference: E-Invoicing.
pdfik einvoice-to-pdf <invoice.xml | -> [flags]
| Flag | Meaning | Default |
|---|---|---|
--profile NAME | Factur-X profile the XML declares: minimum, basicwl, basic, en16931, extended â checked locally before anything is submitted | en16931 |
--template ID | id of a saved invoice template (Dashboard â E-Invoice), sent as template_id; an inline template is not available from the CLI | the account default template |
--webhook URL | callback URL that receives a POST when the job finishes | none |
--test | free test run: full pipeline, sample PDF, no quota used | off |
-o, --output DIR | output directory (created if missing); - streams the PDF to stdout | current directory |
-f, --file-name NAME | file name inside the output directory | <job-id>.pdf |
--timeout DUR | how long to wait for the render (90s, 3m) | 3m |
-q, --quiet | no progress lines; warnings and errors still print | off |
--api-key KEY, --api-url URL | connection overrides; prefer PDFIK_API_KEY / PDFIK_API_URL | environment |
The page flags (--format, --landscape, --margin*, --no-background) do not apply here â an e-invoice's layout comes from its template. minimum and basicwl embed accompanying data only; the CLI prints a note when you pick one of them (silenced by -q).
export PDFIK_API_KEY=sk_live_YOUR_KEY
# Full example: EN 16931 profile, a saved template, a webhook, a named output file
pdfik einvoice-to-pdf invoice.xml \
--profile en16931 \
--template 550e8400-e29b-41d4-a716-446655440000 \
--webhook https://yourserver.com/webhooks/pdf \
-o ./invoices -f invoice-2026-001.pdf --timeout 2m
pdfik einvoice-to-pdf invoice.xml --test # free dry run, sample PDF
cat invoice.xml | pdfik einvoice-to-pdf - -o - > out.pdf # stdin in, stdout out
Rejected requests cost nothing: invalid XML is answered with 422 EINVOICE_XML_INVALID (parsing, profile or XSD check failed) and an unknown --template id with 404 EINVOICE_TEMPLATE_NOT_FOUND; the CLI prints the message and exits with code 1. A job that fails after it was queued exits with code 3 and prints EINVOICE_FAILED.
wkhtmltopdf Compatibility Mode
pdfik wkhtmltopdf takes wkhtmltopdf's own flags and its <input> <output.pdf> arguments,
so for most scripts the migration is an alias:
alias wkhtmltopdf='pdfik wkhtmltopdf'
wkhtmltopdf -s A4 -O Landscape --footer-center 'Page [page] of [topage]' \
https://example.com out.pdf
# Pages behind a login (Pro plan and above)
wkhtmltopdf --username user --password pass https://intranet/report report.pdf
Every wkhtmltopdf flag is either mapped to the API, accepted with a warning (it has no
effect in this pipeline) or refused with a reason (it would change the output) â never
silently ignored. wkhtmltopdf --version and -h answer the way wrappers such as
pdfkit and wicked_pdf expect. The flag-by-flag tables are in
COMPATIBILITY.md.
The --username / --password pair maps to authenticated rendering, which is available
on the Pro plan and above. The credential is sent only to the page's own origin, never
to third-party assets â see Security.
Exit Codes
Scripts can branch on these; pdfik help lists them too.
| Code | Meaning |
|---|---|
0 | PDF written |
1 | the request, render or download failed (API, network, file). If job âĻ queued was printed, the job may still finish â pdfik status <id> / pdfik download <id> |
2 | invalid usage, or a value refused before anything was submitted (nothing charged) |
3 | rendering failed on the server; the error code is printed |
4 | the job was not finished within --timeout; the job id is printed â fetch it later with pdfik download <job-id> |
130 | interrupted (Ctrl-C); an in-flight job keeps running on the server and its id is printed |
Behaviour Worth Knowing
- The API key never leaves the API host. It is stripped from cross-host redirects,
never logged, and plain
http://is refused unless you opt in explicitly. - A job is never created â or charged â twice. A lost submit response is retried under one idempotency key.
- Ctrl-C is clean. No partial file is left behind and the in-flight job id is printed,
so you can still
pdfik downloadit. - Windows: avoid redirecting
-o -in Windows PowerShell 5.1 (powershell.exere-encodes native output as text and corrupts the bytes) â let the CLI write the file, or redirect from cmd.exe / PowerShell 7+.
Next
- Testing â what a
--testrun does and does not do. - Error Codes â the codes printed on exit code
3. - SDKs â the same API from Node, Python and Java.