Skip to main content

Document rendering: HTML and Gotenberg

For: tech leads and anyone deciding how Zyrohs makes documents. Why customer documents move from JasperReports to HTML printed by Gotenberg, what was weighed, and what is still open.

Status, 2026-11-01: decided and in progress. The A4 sale invoice is built and committed on branch aj-doc-render in both repos (2026-11-01). On 2026-11-02 six more were built on the same branch: quotation, sale order, credit note, packing slip, delivery note, and a new payment receipt. None is released. The Jasper documents stay until the new ones are signed off.

The decision

Documents that a shop shares with a customer (invoice, quotation, credit and debit notes, orders) are written as Thymeleaf HTML templates and printed to PDF by Gotenberg, a small service that runs headless Chromium. The backend sends the finished HTML; Gotenberg sends back the PDF.

Decided on 2026-10-31.

Before After
Template templates/*.jrxml (JasperReports) templates/print/*.html (Thymeleaf)
Who prints the PDF Jasper, inside the app Gotenberg (Chromium), a separate service
Layout tools Jasper bands and fixed positions Normal HTML and CSS, including CSS paged media (@page)
Same template for screen and print No Yes. The thermal receipt already uses the same Thymeleaf pipeline

Why

  • Layout. Jasper places text in fixed boxes. Long names, Tamil or Malayalam text, many items and optional blocks (ship-to, payment details) overflowed or left gaps. HTML flows: a long name wraps, a missing block takes no space.
  • One way of building documents. The thermal receipt is already a Thymeleaf template behind IPrintRenderer. The A4 PDF is one more renderer on the same layers (ADR-001), so a new document is a new template, not a new pipeline.
  • Fonts and scripts. Chromium shapes every Indian script and CJK correctly with the Noto fonts installed in the container.
  • Design work is faster. A template can be opened in a browser and changed like any page.

What was weighed

Option Why not
Stay on Jasper Fixed-position layout is the problem being solved. Each new optional block needs manual band work
OpenHTMLtoPDF (Java, in the app) Supports only CSS 2.1. No flexbox or grid, weak support for complex scripts
Chromium inside each app server Every app server would need a browser and its memory. One shared service is easier to size, secure and upgrade
A paid PDF API Customer data would leave our servers

How it is hosted

  • Gotenberg runs in Docker, one instance per server, behind nginx with HTTPS and basic auth. Setup is in the repo at deployments/gotenberg/.
  • Sandbox (dev and QA): https://sandbox.pdf.aaishtech.com, on the Orbit server. Live since 2026-11-01.
  • Production: not decided. It must not use the sandbox. Wherever it runs, it needs its own .env, CPU and memory limits, and an IP allow-list for the app server.
  • The backend sends HTML, the logo and the QR inside the request. Gotenberg is set to fetch nothing from outside, so a template cannot leak data or wait on the network.

Operations detail: Gotenberg PDF engine: setup and operations.


Consequences

  • A second service to run. If Gotenberg is down, the new PDFs fail. The Jasper endpoints are untouched, so the old invoice still works while both exist.
  • Old invoices reprint in the new look once a document switches over, because seller details and the template are read live on every print. Freezing issued documents (a seller snapshot and a template version per document) is planned for the next phase.
  • Reports are separate. Big report PDFs leave Jasper only if a test shows Chromium copes with a 10,000-row report. Until then Jasper stays for reports.

Still open

Item Notes
Where production Gotenberg runs Not decided. Needs an IP allow-list wherever it lands
Freeze issued documents Next phase. Seller snapshot beside the existing buyer snapshot
Report PDFs: Jasper or Chromium Decide after the 10,000-row test
Failover A second instance, with the backend taking a list of URLs
Upgrade checks Compare sample documents before each Gotenberg version bump