Skip to content

Architecture

 client ──HTTP──▶ pressjet serve ──frames over stdin/stdout──▶ pressjet worker (×N)
                  │ keys, rate limits, CORS                    │ pressjet-engine
                  │ admission queue, deadlines                 │ validate → layout → paginate → paint
                  │ result cache, in-flight dedup              │ raster, merge, sign
                  ▼                                            ▼
             access log, metrics                         PDF / PNG bytes

Crates

  • pressjet-engine is a library and pure computation: it reads no files, opens no sockets, starts no threads. pressjet_engine::run(operation, body, limits, signer) takes a request body and returns bytes or a refusal with a kind (request, document, limit). Fonts are compiled in.
  • pressjet-server builds the pressjet binary: the HTTP server, the worker pool, keys, rate limits, metrics and the command line. pressjet render and pressjet check call the engine in the same process, with no server, and print the layout report as text; pressjet guide prints the format guide that the Agent Skill carries.

The server

src/server.rs authenticates (keys.rs), applies the key's origin and operation rules, spends a rate-limit token (limiter.rs), checks the content type and admission bound, reads the body up to its limit and submits it to the pool. Every answer gets a request id, no-store caching, CORS headers when an allowed origin asked, and rate-limit headers when the key has a limit.

src/pool.rs runs jobs. Each worker is the same binary in worker mode, started without the server's environment and with RLIMIT_DATA set. A job frame (protocol.rs) carries the operation, limits, body and, for sign jobs only, the signing identity; a result frame carries a status byte and the output or the refusal. A job past its deadline has its process killed and replaced, so a document that loops or exhausts memory can only end its own worker. Results are cached by (credential digest, operation, body) with a byte bound and a time to live, and identical requests in flight share one render.

HTML

POST /v1/html runs in the same isolated workers as every job: pressjet-html parses the HTML with html5ever and the CSS with simplecss, applies the cascade with the browser defaults, and builds the native document tree (block flow, flexbox, grids, lists, tables, @page margin boxes, running elements, generated content, roles for tagging). The engine then lays it out, paginates and writes it like any document. Nothing is fetched; attached images and fonts are the only resources. What the compiler reads

Optional HTML reference service

Requests with "engine": "reference" go to the WeasyPrint service instead. The API applies the same key, origin, admission and cache rules to POST /v1/html. While holding a pool slot, it opens a private Unix socket to the HTML service. The job carries the remaining deadline, rendering limits and request body. Credentials and signing material stay in the API.

The HTML process validates a closed print profile and lays out the supplied document in a fresh child process. The resolver serves attached images. Standard invoices return positioned JSON to a native worker for validation and PDF writing. Documents with a selected brand font, PDF/UA semantics or box shadows are written inside the isolated child. The PDF/UA finisher uses source element identities to reconnect table fragments across pages and to associate values with their column and row headers.

Inside the reference service, the isolated process can use a Rust row layout engine. Its HTML5 tokenizer handles explicitly nested print markup and passes the resulting tree through the same input policy. The worker measures one representative flex row with the document's fonts and shapes each distinct cell value within the job. Rust resolves fixed and growing column widths, positions the text, and groups complete rows by the space available on each page. The print engine renders the remaining page content, including ambiguous boundary rows and CSS page counters. The worker verifies each group's position and expanded box count before writing the positioned document. If the CSS depends on sibling position, text needs wrapping, or the measured geometry disagrees, it renders the original tree within the existing worker deadline.

The container has no external network connection. The parent verifies the font catalog at startup. Its children have a process memory limit and a wall-clock timer. The socket protocol and both images are versioned and deployed together. Deployment and limits

The engine

Validation (layout/tree.rs) checks the tree against closed sets of node kinds, properties and style keys, with bounds on numbers, strings, depth, nodes, pages and pixels, and builds a typed tree. A refusal names the failing place as a JSON Pointer.

Styles (layout/style.rs) resolve units, expand shorthands and apply inherited values.

Layout (layout/engine.rs) uses Taffy with column direction by default and unrounded coordinates. Text (layout/text.rs) is shaped once with rustybuzz and broken into lines once per width.

Pagination (layout/paginate.rs) lays the remaining content out without a height limit, cuts it at the page bottom, lays the part above the cut out again at the real height, and continues with the rest. Done literally, every page would lay out everything still to come, and a document would cost time in proportion to the square of its length. Instead:

  • A pass lays out only what can decide the next cut. A long column leaves out children that start more than a page and a content area below its top. This applies only to columns whose layout cannot depend on what follows (sized by their content, children that neither grow nor have a set basis, no negative margins, nothing anchored to their bottom, a settled width), and the pass then checks that what it laid out reaches far enough; a pass that cannot prove it is repeated with everything.
  • A cut is planned on the laid-out tree and then applied by moving nodes, so what follows the cut is never copied.
  • Page-number text is filled in only where a pass lays it out.

The result is the same layout node for node (the tests paginate both ways and compare every box and line), at 1.3 to 2.6 ms of CPU time per page from 1 to 500 pages on the page-count benchmark.

Painting (layout/paint.rs) writes the PDF with Krilla, embedding font subsets. No creation date is written, so output is deterministic.

Layout report (layout/check.rs) answers check. It first reads the raw tree for every key and keyword the format does not have, so one answer lists them all with their replacements. A document that passes is validated and laid out by the same code that renders it, and the laid-out pages are measured instead of painted. Each finding carries the JSON Pointer of its node, recorded while the tree is built. See layout-report.md.

Other operations. flow.rs draws text and images top to bottom on fixed pages. raster.rs renders pages to PNG with hayro. merge.rs copies pages with everything they reference, untouched. sign.rs writes a PAdES B-B signature: a CMS SignedData (SHA-256, RSA PKCS#1 v1.5, content type, message digest and signing-certificate-v2 attributes) over every byte outside its placeholder.