PDF Generation
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. The reference material consulted while preparing these pages is listed in the section bibliography. |
Almost every business backend ends up producing PDF files: invoices, statements, contracts, tickets and monthly reports. This section describes how a Java service does that, from the structure of a PDF file to programmatic layout with iText, template-driven reports with JasperReports, signing with PAdES, fillable forms and barcodes. Versions and dates are re-verified when each page is written and are stated as of the date checked.
Running scenario: Bookshelf Billing
Every page uses the same example, the back office of the Bookshelf store used by the Python sections. It is a Spring Boot 4 service on Java 21 that produces:
-
customer invoices with iText, each carrying a VeriFactu-style QR code and a PAdES signature;
-
a monthly sales report grouped by category, with charts and a crosstab, built with JasperReports from PostgreSQL;
-
an editable customer onboarding form (AcroForm) that is returned signed.
No page uses real certificates, keys, tax identifiers or customer data. Signing examples use a test certificate authority generated on the page, timestamps come from a public test time-stamping authority, and tax-authority examples target pre-production endpoints only.
Reading paths
-
Report designer. Start with the template-report approach and the JasperReports pages, then the reports-from-data material and the conformance pages.
-
Backend developer. Start with the introduction, the PDF file structure and the Spring Boot setup, then iText layout, forms and barcodes.
-
Signing and compliance. Start with the standards and conformance pages, then PAdES signatures, timestamps and long-term validation, and the regulated QR codes for invoices.
Pages
Foundations
-
Introduction and Approaches: the four approaches (programmatic layout, template reports, HTML to PDF and XSL-FO) and the licences that decide between them.
-
How a PDF File Works: objects, cross-reference table, content streams and incremental updates.
-
PDF Standards and Conformance: PDF 1.7 and 2.0, PDF/A, PDF/UA and the other conformance families.
-
Getting Started with Spring Boot: dependencies, configuration and a first invoice from a Spring Boot service.
-
Generating Reports from Databases and Services: feeding documents from databases, REST services and files.
iText
-
Architecture and Modules, Document Lifecycle, Layout Elements, Fonts and Unicode, Colours, Images and SVG and Tables: the module map, documents, layout elements, fonts, images and tables.
-
Renderers and Custom Layout, Page Events, Low-level Canvas and Navigation, Annotations and Actions: custom renderers, headers and footers, the canvas, links and actions.
-
Manipulating Existing PDFs, Text Extraction and Parsing and HTML to PDF with pdfHTML: existing files, extraction and HTML.
-
PDF/A and PDF/UA, Encryption and Permissions, Add-ons and Testing and Performance: conformance, protection, add-ons and testing.
JasperReports
-
Architecture and Lifecycle, JRXML Design, Expressions, Parameters, Fields and Variables, Groups, Sorting and Filtering and Data Sources: lifecycle, design, expressions, groups and data.
-
Subreports, Datasets, Tables and Lists, Crosstabs, Charts, Styles, Templates and Markup and Fonts and Internationalization: subreports, crosstabs, charts, styles and fonts.
-
Scriptlets and Extensions, Hyperlinks, Bookmarks and Books, PDF Export Configuration and Large Reports and Performance: scriptlets, links, exporter configuration and large reports.
-
Spring Boot Integration and Security Hardening: Spring Boot integration and hardening.
Digital signatures
-
Digital Signature Fundamentals and PAdES Baseline Levels: concepts and the four PAdES baseline levels.
-
Signing with iText and Signing with PDFBox and EU DSS: signing with the three main libraries.
-
Remote, HSM and Deferred Signing and Validation and Long-term Validity: remote and hardware keys, validation and archival.
Forms and barcodes
-
Editable Forms: Fundamentals, with iText and with JasperReports and PDFBox: AcroForm fields, filling and flattening.
-
Barcodes and QR Codes: Fundamentals, with iText, ZXing and Okapi, in JasperReports and Regulated QR Codes: barcodes, QR codes and the regulated invoice QR codes.
Beyond
-
Alternatives and Other Ecosystems, Testing and Production Practices and What’s Changed and Migration: other libraries and ecosystems, testing and production, and migration from the older books.
-
Cheat Sheet (PDF): a single-page printable reference.
Existing pages this section builds on
-
Java Reference for the language features used by the examples.
-
Spring Boot for REST endpoints, storage, data access and batch.
-
Media Optimization for images that end up inside generated documents.
Bibliography
The pages of this section are written against the official documentation listed here and verified on 2026-10-09 against the versions stated on each page: iText 9.8.0, pdfHTML 6.3.4, JasperReports 7.0.8, Apache PDFBox 3.0.8, EU DSS 6.5, ZXing 3.5.4 and Bouncy Castle 1.86.
Books
Three books were consulted for the concepts they cover and the order in which they present them. They are cited and linked to their official pages. No text, code listing, figure or dataset from them is reproduced, and they were not used as the source of any code example. All three predate the versions above, and the pages say in prose where a book is outdated and show the current approach (the findings are collected in What’s Changed and Migration).
-
Bruno Lowagie, iText in Action: Creating and Manipulating PDF, first edition, Manning, 2006 (print 2007), ISBN 978-1-932394-79-5. Targets iText 1.4 and the
com.lowagiepackages, on JDK 1.4 and PDF 1.6. Publisher page. A second edition exists (Manning, 2010, for iText 5), publisher page; it was not consulted. -
Teodor Danciu and Lucian Chirita, The Definitive Guide to JasperReports, Apress, 2007, ISBN 978-1-59059-927-3 (eBook 978-1-4302-0521-0). Targets JasperReports 1.3.x and iText 1.x. Publisher page at Springer (Apress is a Springer imprint).
-
Teodor Danciu, The JasperReports Ultimate Guide, version 1.0, self-published, 2002, no ISBN. Targets JasperReports 0.4 and 0.5 and the
dori.jasperpackages. The guide has no publisher page. The project’s official site, JasperReports library documentation, is its editorial home, and lists a later edition as JasperReports Ultimate Guide 3.
JasperReports
-
JasperReports 7.0.8 documentation: configuration reference, sample reference (one README per sample) and API documentation
Signatures, PDF libraries and validation
-
Apache PDFBox, its getting started guide and the example sources
-
veraPDF and its documentation
-
FreeTSA, the public test time-stamping authority used by the examples
Standards and specifications
-
ISO 32000-2:2020, PDF 2.0: ISO catalogue entry
-
ISO/IEC 18004:2015, QR code: ISO catalogue entry
-
ETSI: EN 319 142-1, PAdES, EN 319 142-2, TS 119 142-3, EN 319 102-1 and EN 319 422
-
IETF: RFC 3161, time-stamp protocol, RFC 5280, X.509, RFC 5652, CMS and RFC 6960, OCSP
-
CSS Paged Media Module Level 3 and Unicode Bidirectional Algorithm
Regulations and invoice formats
Alternatives and other ecosystems
The official sites of the libraries compared in Alternatives and Other Ecosystems.
-
Gotenberg, Playwright and Puppeteer
-
WeasyPrint and ReportLab