How to create PDF files with Java and OpenPDF

Miguel Doctor Yuste
9 min readNov 7, 2022

A guide to OpenPDF, a free and open source alternative to create PDF documents with Java.

This article is a Java adapted version from my original article published on Better Programming medium publication (here)

Environment

This step by step tutorial is written based on the following requirements:

  • Operating System: MacOS Catalina 10.15.7
  • Java version: Openjdk version “11.0.16”
  • IntelliJ IDEA: 2022.2.2 (Community Edition)

Objectives

This tutorial aims to provide a quick hands-on reference to create and edit PDF files using Java language with the help of OpenPDF.

According to the official Github page of the project, OpenPDF is a free Java library for creating and editing PDF files with a LGPL and MPL open source license.

Ok, that’s very nice but if you have ever searched something about PDF and Java, I am sure the first option you found was iText. So why shouldn’t we use iText but OpenPDF instead?

OpenPDF vs iText

First, let’s be clear about it… iText is one of the best alternatives when looking for a PDF generation library in Java, that is out of the discussion. Nevertheless, it comes with a huge handicap… iText is open sourced using AGPL license which means that once used in your application, you need to fully share your application…

--

--

Miguel Doctor Yuste

Ph.D, AI Data Scientist, Software Engineer, Cloud Architect, Systems Engineer, happy father and happy husband :)