PDF generation in microservice landscapes
A client wanted to extend their microservice landscape with PDF generation and distribution – multilingual, without costly deployments and without licensing pitfalls.
Generate and distribute PDF documents – integrated into the client’s existing AWS landscape.
A dedicated microservice renders PDFs from HTML templates with Thymeleaf, Flying Saucer and OpenPDF and is connected via REST.
Templates and translations can be swapped without a deployment – with building blocks licensed for commercial use.
HTML in, PDF out
The project uses Flying Saucer to turn HTML into PDF. Underneath, either iText 5 or OpenPDF can serve as the PDF library – the resulting documents are identical in size and appearance.
The recommendation was OpenPDF: it is licensed under the LGPL and can be used in commercial environments without issues. In addition, the Flying Saucer team ended support for iText 5 in May 2024.
Swap without deploying
A key requirement: change PDF templates and translations without redeploying every time.
- A dedicated microservice handles PDF generation.
- It connects to the existing AWS landscape via REST interfaces.
- HTML templates and translations live in a database and are loaded dynamically.
The underestimated licensing question
The font embedded in the PDFs needs special attention – especially for other scripts such as Cyrillic. Popular fonts like Arial require a license and can cause considerable costs.
The solution: the free Noto font family. It supports more than 800 languages and may be redistributed freely under the SIL Open Font License.
Up and running on GitHub
A working prototype is publicly available on GitHub. It delivers PDFs synchronously and can easily be adapted for asynchronous distribution.
- Java 21
- Kotlin
- Spring Boot
- Spring Data
- Hibernate
- PostgreSQL
- Docker
- Docker Compose
- Testcontainers
- Rest Assured
- JUnit
- Maven
