Self-hosting¶
Pressjet is one binary, pressjet, shipped as the image ghcr.io/tonysantana1492/pressjet
(linux/amd64 and linux/arm64) and as release binaries. The image has no shell and runs as a
non-root user.
Run it¶
export PRESSJET_API_KEY="$(openssl rand -hex 32)"
docker run -d --name pressjet -p 127.0.0.1:8080:8080 \
--read-only --memory 1g --cpus 2 \
-e PRESSJET_API_KEY \
ghcr.io/tonysantana1492/pressjet:0.1.0-beta.7
GET /health answers {"status":"ok"}; the image's HEALTHCHECK uses pressjet healthcheck, so
it works without a shell. GET /v1/info lists the operations, fonts and limits the server offers.
Examples for Docker Compose and Kubernetes are in deploy/.
API keys¶
A server needs keys; it refuses to start without them.
One key. PRESSJET_API_KEY accepts a single secret, allowed every operation. Good for one
backend talking to its own Pressjet.
A key file. PRESSJET_API_KEYS_FILE points to a JSON file that lists many keys, each with its
own name, permissions and rate limit. The server stores only the SHA-256 of each key, so the file
can be read by operators without revealing usable keys.
pressjet keys new --id billing-service
pressjet keys new --id customer-portal --publishable
Each command prints the key once and the entry to add to the file:
{
"keys": [
{ "id": "billing-service", "hash": "sha256:…" },
{ "id": "reports", "hash": "sha256:…", "operations": ["generate", "merge"],
"rateLimit": { "perMinute": 600, "burst": 100 } },
{ "id": "customer-portal", "hash": "sha256:…", "kind": "publishable",
"allowedOrigins": ["https://app.example.com"] },
{ "id": "old-backend", "hash": "sha256:…", "disabled": true }
]
}
| Field | Meaning |
|---|---|
id |
Name in logs, metrics and rate limits: letters, digits, -, _, .; at most 64. |
hash |
sha256: and the hex SHA-256 of the key, as keys new prints it. |
kind |
secret (default) or publishable. |
operations |
Allowed operations; default all for secret keys, generate, preview and check for publishable ones. A publishable key can never sign. |
allowedOrigins |
Exact browser origins. Required for publishable keys; on a secret key it enables CORS answers for those origins. |
rateLimit |
perMinute and optional burst (default a sixth of perMinute). Omit for no limit. |
maxConcurrent |
Requests this key may have in progress at once (1–8192); default PRESSJET_MAX_CONCURRENT_PER_KEY. |
disabled |
true keeps the entry but stops the key from working. |
The server checks the file every five seconds and reloads it when its contents change. A file that no longer parses is reported on standard error and the previous keys stay in force, so a typo never locks everyone out. To rotate a key: add the new one, move clients to it, then disable or remove the old one.
Secret and publishable keys. Secret keys start with pj_sk_ and belong on servers only.
Publishable keys start with pj_pk_ and are meant to ship inside a web page: the server accepts
them only on requests whose Origin is in the key's list and only for the key's operations; only those
answers carry Access-Control-Allow-Origin. Preflight requests all get the same answer, so they
reveal nothing about which origins have keys. Give them a modest rate limit, because
anyone can copy a key from a page.
PRESSJET_AUTH=disabled turns authentication off entirely. Use it only on a private network that
nothing untrusted can reach; the server warns at start.
Configuration¶
| Variable | Default | Meaning |
|---|---|---|
PRESSJET_HOST |
0.0.0.0 |
Address to listen on. |
PRESSJET_PORT |
8080 |
Port; 0 picks a free one and prints it. |
PRESSJET_API_KEY |
One secret key (32+ characters). | |
PRESSJET_API_KEYS_FILE |
Path of the key file. | |
PRESSJET_AUTH |
disabled to run without keys. |
|
PRESSJET_RATE_LIMIT_PER_MINUTE |
0 (none) |
Rate limit for PRESSJET_API_KEY or a server without keys. |
PRESSJET_RATE_LIMIT_BURST |
a sixth of the above | Burst for that limit. |
PRESSJET_WORKERS |
CPU count | Worker processes, one job each at a time. |
PRESSJET_MAX_QUEUE |
32 |
Requests that may wait for a worker before new ones get 503 server_busy. |
PRESSJET_MAX_CONCURRENT_PER_KEY |
half of workers + queue | Requests one key may have in progress at once, so one caller cannot take every slot. |
PRESSJET_MAX_CONNECTIONS |
1024 |
Open connections at once; more wait in the kernel's queue. |
PRESSJET_HEADER_TIMEOUT_MS |
10000 |
Time for request headers to arrive; also closes idle keep-alive connections. |
PRESSJET_WRITE_TIMEOUT_MS |
30000 |
Close a connection if a pending response write makes no progress for this long. |
PRESSJET_BODY_TIMEOUT_MS |
10000 |
Time for an admitted request's body to arrive. |
PRESSJET_TIMEOUT_MS |
30000 |
Deadline for rendering, including the wait in the queue. |
PRESSJET_MAX_REQUEST_BYTES |
20 MiB | Largest request body. |
PRESSJET_MAX_RESPONSE_BYTES |
64 MiB | Largest PDF or preview a job may produce. |
PRESSJET_MAX_PAGES |
200 |
Pages per document (up to 2,000). |
PRESSJET_MAX_NODES |
20000 |
Nodes per document. |
PRESSJET_MAX_PIXELS |
24,000,000 | Image pixels per request, counted from image dimensions. |
PRESSJET_WORKER_HEAP_MB |
512 |
Memory cap of each worker process. |
PRESSJET_CACHE_BYTES |
64 MiB | Result cache size; 0 disables it. |
PRESSJET_CACHE_TTL_MS |
60000 |
How long a cached result is kept. |
PRESSJET_FONTS_DIR |
A folder of .ttf and .otf files (64 at most) installed for every document at startup, in the server, its workers and the CLI. /v1/info lists their families. Fonts whose license forbids embedding stop the start. |
|
PRESSJET_ACCESS_LOG |
true |
One JSON line per request on standard output. |
PRESSJET_LOG_FAILURES |
false |
Also write each refusal's reason to standard error. |
PRESSJET_METRICS_TOKEN |
Enables GET /metrics behind this bearer token (32+ characters). |
|
PRESSJET_SIGNING_P12_BASE64 |
PKCS#12 certificate and key for /v1/sign, base64. |
|
PRESSJET_SIGNING_P12_PASSPHRASE |
Its passphrase. | |
PRESSJET_SIGNING_LOCATION |
Location shown by PDF readers. | |
PRESSJET_SIGNING_CONTACT |
Contact shown by PDF readers. | |
PRESSJET_VERIFICATION_KEY |
Seed of the Ed25519 key that signs verification codes, base64 (pressjet keys verification makes one). The server, its workers and the CLI sign with it; /v1/info lists the public half. |
A value out of range stops the start with a message naming the variable.
Every successful response says how it was produced in x-pressjet-served: rendered, shared
(an identical request was rendering at the same moment and its result answered both) or cache.
Benchmarks should send distinct documents, or read this header, to measure rendering.
Sizing and scaling¶
- A worker renders one job at a time, so
PRESSJET_WORKERSequal to the CPUs is right for most loads. A worker may grow up toPRESSJET_WORKER_HEAP_MB; a 500-page invoice neededPRESSJET_WORKER_HEAP_MB=900and fails at the default 512. A fresh one-worker container used 2.8 MiB, and the warm service measured about 15–28 MiB on the invoice benchmark, including charged file cache. - On the page-count benchmark a page cost
1.3–2.6 ms of CPU, and one pinned CPU served 593 one-page documents per second to one client
(p95 2.2 ms) and 791 to eight clients (p95 13.7 ms). Heavy images and very dense pages cost
more. Measure your own documents with
bench/bench.py. - The server keeps no state that matters between requests (the cache is an optimization), so scale out by running more instances behind a load balancer. Rate limits are per instance: divide a key's limit by the number of instances, or put a gateway in front for exact global limits.
503 server_busywithRetry-After: 1means the queue is full: add instances or workers. The SDKs retry it automatically.- Each key may have only its share of requests in progress (
PRESSJET_MAX_CONCURRENT_PER_KEYor the key'smaxConcurrent); beyond it the key gets429 rate_limited, so one busy or slow caller cannot starve the others. Connections are capped (PRESSJET_MAX_CONNECTIONS) and must send their headers and body within their deadlines.
Observability¶
- Access log. Each request writes one JSON line: time, request id, key id, operation, status, duration and sizes. Document content is never logged.
- Request ids. A safe
X-Request-Idfrom the caller is kept, otherwise one is made; it is in the response header, the access log and every error body. - Metrics. With
PRESSJET_METRICS_TOKENset,GET /metricsserves Prometheus text: requests by operation and status, time spent, queue and worker gauges, cache hits.
Security model¶
- Documents are data, never code: every object is checked against closed lists of node kinds, properties and styles, with bounds on numbers, text, depth, nodes, pages and pixels.
- Nothing is fetched: images arrive in the request. Nothing is read from disk while rendering; fonts are compiled in.
- Each job runs in a separate worker process started without the server's environment, with a
memory cap (
RLIMIT_DATA) and a deadline after which it is killed and replaced. Only sign jobs receive the signing key. - Error details describe the request's structure (for example
unknown font family at /children/0/…/fontFamily); they repeat no document content beyond the key names the caller wrote, shortened. - Cached results are kept per API key, so one tenant cannot detect another's documents by timing.
- Keys are compared by their SHA-256 digests; the key file holds no usable secrets.
Report vulnerabilities as described in SECURITY.md.
Signing¶
/v1/sign adds a PAdES B-B signature (ETSI.CAdES.detached, SHA-256, RSA) with the server's
certificate. Provide the certificate and key as a PKCS#12 file:
openssl pkcs12 -export -inkey key.pem -in cert.pem -certfile chain.pem -out signer.p12
export PRESSJET_SIGNING_P12_BASE64="$(base64 < signer.p12 | tr -d '\n')"
A certificate that cannot be read stops the start. Without one, /v1/sign answers
501 signing_not_configured and /v1/info leaves sign out of its operations.
Verification codes¶
Documents with the verification property carry a code on every page; see
Barcodes and verification codes. To sign those codes, make a key once and
keep its seed with the server's other secrets:
pressjet keys verification
export PRESSJET_VERIFICATION_KEY='<the seed it printed>'
A seed that cannot be read stops the start. Without one, codes carry no signature. Publish the
public key where verifiers can find it; /v1/info also answers it as verificationKey.
/v1/verify and pressjet verify read scanned codes back.
Without Docker¶
Release binaries are static Linux executables. Build one yourself with Rust 1.100+:
cargo build --release -p pressjet-server
./target/release/pressjet --help
pressjet render document.json -o document.pdf renders a file without a server, which is handy for
scripts and for checking a document.
The local CLI uses the same PRESSJET_MAX_PIXELS setting for render, check, template,
dev and redact. The default is 24,000,000 pixels and the accepted range is 1 to 200,000,000.
This command raises the budget to 100 million pixels for one render.
PRESSJET_MAX_PIXELS=100000000 pressjet render photos.json -o photos.pdf
Print existing HTML¶
POST /v1/html needs nothing extra: the workers compile the HTML and its CSS into the native
format and render it with the engine (what the compiler reads). The response header
x-pressjet-engine: native says so.
The optional reference service¶
A deployment may also run the WeasyPrint service and send "engine": "reference" to compare
with it. It listens on a private Unix socket shared with the Rust server. From the repository root, configure the key file as described above and build both images from the same checkout.
docker compose -f deploy/docker-compose.yml -f deploy/html.compose.yml up -d --build
Without the socket, a request with "engine": "reference" gets 501 html_not_configured. Send populated UTF-8 HTML with "engine": "reference" to the same authenticated server used for native documents; the response header x-pressjet-engine: reference says the service printed it.
curl --fail-with-body http://localhost:8080/v1/html \
-H "Authorization: Bearer $PRESSJET_API_KEY" -H 'Content-Type: application/json' \
-d '{"version":1,"engine":"reference","html":"<h1>Invoice 42</h1><p>Total due: 100 USD</p>"}' -o invoice.pdf
The print profile accepts paragraphs, headings, tables, repeated table headers, running headers and footers, inline print CSS and attached stylesheets. Supply PNG/JPEG bytes under images keyed by the exact resource name used in the document. External stylesheet links, scripts, event attributes, CSS imports and unattached resources are refused. See the tested templates and fidelity measurements.
Set PRESSJET_HTML_MAX_BYTES for Compose to select an HTML source limit between 16,384 (default) and 4,194,304 bytes, and PRESSJET_HTML_CONCURRENCY (1 to 64, default 2) for the conversions it runs at once. A refusal names every element, property and font the reference profile refused, in the problem's detail; profile may be pdf-ua-1 or pdf-a-2b. A font that is not installed is refused rather than replaced. The JSON envelope is limited to the smaller of 4 MiB and the configured HTTP body limit. Up to eight stylesheets share 16 KiB. Up to 16 image attachments or explicit omissions share a 2 MB attachment budget. Images share four million pixels or the configured pixel limit, whichever is smaller. Admission, key permissions, tenant cache partitioning, page and node limits and the render deadline also apply. Publishable keys require an allowed origin and explicit permission for the HTML operation.
Each conversion runs in a fresh subprocess with a ceiling of 512 MiB of virtual memory, lowered by PRESSJET_WORKER_HEAP_MB. One service instance can run two conversions concurrently. Compose gives it a read-only root filesystem, private writable temporary storage, a process cap and no network interface for external connections. Mount the socket volume only in its matching API container. Build and restart the pair together whenever updating the protocol, renderer or fonts.
Row layout inside the reference service. The reference service automatically accelerates a run of at least eight matching top-level flex rows with fixed or growing text columns, including Latin invoice text and currency symbols. Page-edge rows, complex selectors, HTML tables, attached resources and PDF/UA retain their print-layout support. To compare a template against the reference renderer, set PRESSJET_HTML_NATIVE_ROWS=0 on the HTML service container and recreate it. Set it to 1 to enable the optimization again. This setting affects only "engine": "reference" requests; the default native path does not use it. Implementation and fidelity checks
Brand fonts. Install trusted, static TrueType files read-only under /usr/local/share/fonts in the HTML container. Set PRESSJET_HTML_FONTS on that container to a comma-separated list of their family names. Select a default with the request's fontFamily. A CSS declaration on an element can override the default. The service checks the declared faces and embedding flags at startup. The branded and tagged PDF writer rejects missing glyphs and failed font subsetting. Supply only fonts licensed for every tenant of that deployment. Use a separate deployment for a private tenant catalog.
Accessible invoices. Select "profile":"pdf-ua-1" to retain semantic HTML structure in the PDF. Include an HTML language, a document title, descriptive headings, meaningful table headers and image alternatives. Use column or row scope on headers. Each data cell must have an associated header. Repeated header text stays visible on each page and appears once in the logical table. Validate each template and review reading order, language and alternative text with assistive technology. The reference invoice and a list sample are checked with veraPDF during CI.
To reproduce the deployment check on Linux, install Docker, Python 3 and Poppler, build the server and run:
docker build -t pressjet:local .
services/html/check-deployment.sh pressjet:local
Measure HTML and native invoices¶
On a Linux cgroup v2 host, pass a CSV destination to the deployment check. To regenerate the chart, install Matplotlib in the plotting environment.
services/html/check-deployment.sh pressjet:local results.csv
python3 bench/html_service.py --plot results.csv results.png
The command measures the deployment under test. The figures below come from the service benchmark of 29 November 2026 on an Intel Core i7-1265U: a release build, one pinned logical CPU and 1 GiB per container, one worker, and 21 warm sequential requests per cell. HTML went to POST /v1/html on the default native path.
| Invoice items | Input | HTTP median | CPU median | Peak RAM¹ |
|---|---|---|---|---|
| 1 | HTML | 2.51 ms | 1.98 ms | 15.07 MiB |
| 1 | JSON | 2.00 ms | 1.52 ms | 15.32 MiB |
| 100 | HTML | 13.46 ms | 12.39 ms | 16.18 MiB |
| 100 | JSON | 7.77 ms | 7.43 ms | 16.39 MiB |
| 500 | HTML | 57.31 ms | 55.72 ms | 28.04 MiB |
| 500 | JSON | 31.95 ms | 31.47 ms | 28.41 MiB |
¹ Median of per-request peaks of the container's cgroup memory.current, which includes the warm service and charged file cache. These samples measure one host and workload. Summary CSV
Render a stored template¶
The template endpoint is available in builds that advertise template-render in GET /v1/info.
Set PRESSJET_TEMPLATE_DIR to an operator-owned, read-only mount. At startup the server
loads up to 128 files named <id>.template.json, up to 1 MiB each and 16 MiB in total.
IDs start with a lowercase ASCII letter or digit and can contain those characters and
hyphens, up to 64 characters. Restart with the previous directory to revert a change.
Secret keys with the default permissions include template-render. Scoped secret keys
require that operation explicitly.
Use a local candidate built by the Compose example.
export PRESSJET_API_KEY="$(openssl rand -hex 32)"
docker compose -f deploy/templates.compose.yml up --build -d
curl --fail http://127.0.0.1:8080/health
jq -c '{version: 1, data: .}' docs/agents/examples/invoice.data.json |
curl --fail -H 'Content-Type: application/json' \
-H "Authorization: Bearer $PRESSJET_API_KEY" \
--data-binary @- http://127.0.0.1:8080/v1/templates/invoice/render -o invoice.pdf
pdfinfo invoice.pdf
The fixture produces two pages. The PressJet-Template-Digest response header identifies
the loaded bytes. The caller supplies data only. The server applies its normal request size,
queue, timeout and page limits.
Template guide · HTTP contract
Try the local console¶
The local console adds a loopback interface with project keys, validation and activation of template revisions, and a local usage history.
Certify a PDF¶
Add "certify": true to the existing signature object in POST /v1/sign to declare the
document final. The signing service adds the document modification policy to the same
certificate-backed signature. The certification option requires an unsigned PDF with
no existing permissions dictionary. Use the recipient PDF verifier
with the recipient's public trust anchors to check signature integrity, chain trust and the
no-edits certification policy.
Durable rendering jobs¶
Enable the durable jobs pilot for HTML and stored templates with PostgreSQL.