Sitemap
Zeeshan Wazir

Zeeshan Wazir

I'm a programmer who loves to code and find optimal solution to the problems.

3 Java PDF Libraries that Java Devs mostly Work with

9 min readFeb 27, 2023

--

Updated October 2026: This article has been revised with IronPDF for Java’s 2025–2026 releases, current licensing for all three libraries, and an updated Maven dependency.

Java is a popular programming language and used by millions of programmers to develop software applications. Millions of devices across the world use Java. If you are Java developer you must have felt the need to integrate PDF functionalities in your application.

PDF (Portable Document Format) is a digital document format which is also popular and used to send and receive data over internet. The reason PDF documents are still used is that it preserves the formatting of data and it opens the same on every platform. However, developers face problems when working with PDF files programmatically in Java.

To overcome the problems while modifying PDFs, now there are a bunch of Java PDF libraries available. Here in this article, I will discuss 3 most popular Java PDF library which you can use to create PDF files along with editing them.

IronPDF: Java PDF Library

A Java PDF Library

IronPDF is a robust Java library for generating and editing PDF documents. The API is user-friendly which allows developers to quickly generate high quality and professional PDFs from HTML in all types of Java projects. It’s IronPDFEngine prioritizes ease of use, accuracy and speed.

IronPDF Java PDF library is used to create, edit and update PDF files with just a few lines of code. It provides various operations for manipulating PDF documents such as creating pdf files, extract text, extract images, and insert text or metadata into existing PDF files.

The library provides powerful features like making PDF documents safe and secure with user and owner password, editing restrictions, digital signatures, create responsive layouts, header and footer, margins and other page settings.

IronPDF also provides conversion from other file formats to PDF files. It helps to convert HTML file or string to PDF document. It makes PDF creation very flexible and easy. PDF can directly be created from a webpage URL with CSS and JavaScript embedded. It provides a pixel perfect PDF without any additional software or hardware.

Let’s look at some code examples using IronPDF. First, make sure the dependency is added correctly:

<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>2026.10.1</version>
</dependency>

HTML to PDF Documents

import com.ironsoftware.ironpdf.*;  
import java.io.IOException;
import java.nio.file.Paths;

// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");

// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));

// Render the HTML as a PDF. Stored in myPdf as type PdfDocument;
PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!");

// Save the PdfDocument to a file
myPdf.saveAs(Paths.get("html_saved.pdf"));

PDF Forms

import com.ironsoftware.ironpdf.PdfDocument;  
import com.ironsoftware.ironpdf.render.ChromePdfRenderOptions;
import java.io.IOException;
import java.nio.file.*;

// #1 Use Case: Create a PDF Form from HTML Form Markup
Path outputLocation = Paths.get("assets/BasicForm.pdf");
String formHTML = "<html>"
+ "<body>"
+ "<h2>Editable PDF Form</h2>"
+ "<form>"
+ "First name: <br> <input type='text' name='firstname' value=''> <br>"
+ "Last name: <br> <input type='text' name='lastname' value=''>"
+ "</form>"
+ "</body>"
+ "</html>";

ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();
renderOptions.setCreatePdfFormsFromHtml(true);
PdfDocument.renderHtmlAsPdf(formHTML, renderOptions).saveAs(outputLocation);

// #2 Use Case: Writing Values to the PDF Form
PdfDocument form = PdfDocument.fromFile(outputLocation);

// Set the value of the firstname input field.
form.getForm().setFieldValue("firstname", "Minnie");

// Set the value of the lastname input field.
form.getForm().setFieldValue("lastname", "Mouse");

// Save the changes to the PDF Form.
form.saveAs(Paths.get("assets/BasicForm_Filled.pdf"));

Print PDF Files

import com.ironsoftware.ironpdf.PdfDocument;
import java.awt.print.PrinterException;

PdfDocument pdf = PdfDocument.renderHtmlAsPdf("<h1>Created with IronPDF!</h1>");
try {
pdf.print();
} catch(PrinterException exception) {
System.out.println("Failed to print PDF");
exception.printStackTrace();
}

In the above code examples you have seen how IronPDF provides flexibility to generate, format and edit PDFs. You can check further code examples from here.

What’s New in IronPDF for Java (2025–2026)

Since this article was first published, IronPDF for Java has grown well beyond basic HTML-to-PDF conversion, with new capabilities for accessibility, document optimization and navigation.

  • PDF Accessibility (PDF/UA-2): Support for PDF/UA-2 (ISO 14289–2:2024), added in December 2025. Since October 2026, document structure, language and accessibility metadata are also preserved when merging, importing or securing PDFs.
  • Advanced PDF Compression: AdvancedCompressionOptions (June 2026) gives fine-grained control, including image DPI downsampling, JPEG quality and structure-tree removal. October 2026 added opt-in bitonal (1-bit) compression for smaller, sharper scanned documents.
  • PDF Linearization: Create linearized (“fast web view”) PDFs as files, bytes or streams, and check whether a PDF is already linearized (May 2026).
  • Automatic Bookmarks and Links: Generate hierarchical bookmarks from HTML headings (H1–H6) during rendering, filtered by heading level or CSS selector, and add clickable links to specific pages and positions with LinkAnnotation (May 2026).
  • Table of Contents: Configurable table of contents titles, with an optional title entry (October 2026).
  • Digital Signatures: Sign an existing named signature field (October 2026), plus fixes for signature compatibility and timestamp time zones (July 2026). Note that a document now takes one signature at a time: to add another, save, reopen and sign again.
  • Form-Field Fonts: Control or suppress automatic font embedding in form fields (June 2026).
  • Rendering Performance: Fewer internal render calls and reuse of browser tabs (April 2026), plus connection lifecycle management and clearer errors for stalled renders in long-running applications (July 2026).

If you already use compression, note that compressImages() is deprecated in favor of compressAndSaveAs(), compressPdfToBytes() and compressPdfToStream().

Get Zeeshan Wazir’s stories in your inbox

Join Medium for free to get updates from this writer.

These updates make IronPDF worth considering for Java applications that need more than straightforward PDF generation, particularly where accessibility, file size and automated HTML-to-PDF workflows matter. For full details, see the IronPDF for Java Changelog.

License

IronPDF is a commercial library with perpetual licenses (no recurring license fees). Licenses start at $999 for Lite (1 developer, 1 location, 1 project), with Plus, Professional and Unlimited tiers for larger teams. Each license includes one year of support and updates, and further coverage can be purchased separately. A 30-day free trial unlocks full functionality for development and testing. See the IronPDF for Java licensing page for current pricing.

Press enter or click to view image in full size
IronPDF — Licensing

iText: Java PDF Library

Press enter or click to view image in full size
iText — Java PDF Library

iText is an open source Java library which allows developers to create pdf files, read pdf files, and manipulate them effortlessly. It is a complete PDF toolkit which is well documented and have a versatile PDF engine which easily integrates not only in your workflows but also in your applications, processes or products.

iText allows you to create professionally formatted PDF documents with its pdfHTML add-on. It converts HTML file or string to standard PDF/A compliant, accessible and searchable PDF file. It also supports multiple language and writing using pdfCalligraph, which is a closed source code add-on.

iText also helps make PDF data safe and secure by redacting confidential data using pdfSweep. It can completely remove content from PDF file instead of just covering it up. iText library helps optimizing PDF documents for size or speed, by allowing developers to control optimization options.

The library also provides pdfOffice add-on which allows conversion from office documents to PDF, while preserving the entire formatting in the source file. If you want to convert .csv or .txt files to PDF document, iText 7 core can be used.

Lets have a look at some code examples using iText

Create PDF files

import com.itextpdf.kernel.pdf.*;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;
import java.io.*;

public class HelloWorld {
public static final String DEST = "/myfiles/hello.pdf";

public static void main(String args[]) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(DEST));
Document document = new Document(pdf);
String line = "Hello! Welcome to iTextPdf";
document.add(new Paragraph(line));
document.close();
System.out.println("Awesome PDF just got created.");
}
}

HTML File to PDF File

import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.ConverterProperties;

public class HelloWorld {
public static void main() throws IOException {
// IO
File htmlSource = new File("input.html");
File pdfDest = new File("output.pdf");
// pdfHTML specific code
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.convertToPdf(new FileInputStream(htmlSource),
new FileOutputStream(pdfDest), converterProperties);
}
}

Word Document to PDF Document

import com.itextpdf.licensekey.LicenseKey;
import com.itextpdf.pdfoffice.OfficeConverter;
import com.itextpdf.pdfoffice.OfficeDocumentConverterProperties;
import com.itextpdf.pdfoffice.OfficePageRange;
import java.io.File;
import java.io.IOException;
public class Office {

public static void main(String[] args) throws IOException {
LicenseKey.loadLicenseFile("license.xml");
File pdfOutFile = new File("out_office.pdf");
File demoFile = new File("input.docx");
// converts pages between 1 to 8
OfficeConverter.convertOfficeDocumentToPdf(demoFile, pdfOutFile, new OfficeDocumentConverterProperties()
.setPageRange(new OfficePageRange().addPageSequence(1, 8)));
}
}

In the above code examples, you can see that how easy it is to create and manipulate PDFs using iText. The code is not complicated and can be understood easily. For more information on iText you can visit the website through this link.

License

iText is dual-licensed. The open-source version is available under the AGPLv3, which requires you to release the full source code of your own application if you use it. For closed-source or commercial use, iText offers commercial licenses (an OEM license or an annual volume-based subscription), with pricing available by quote. A 30-day free trial is available.

Apache PDFBox: A Java PDF Library

Press enter or click to view image in full size
Apache PDFBox — A Java PDF Library

Apache PDFBox is an open source Java tool which allows creation of new PDF documents with ease. It also helps in manipulating existing PDF documents in Java Package. It includes series of command-line utilities for performing various PDF operations. It is published under Apache License v2.0.

This library allows to extract text from PDF files. It also helps to extract data from PDF forms and also allows to fill them. It provides all PDF features with validating PDF files against PDF/A standard. You can also save PDF files as images in JPEG or PNG format.

With Apache PDFBox you can print a PDF document with the help of standard Java printing API. It also helps you digitally sign PDF files. Other important functionality includes encrypting and decrypting PDFs, merging and splitting, debugging, converting text and images.

Lets have a look at some code example using Apache PDFBox.

Create PDF Document

import java.io.IOException;   
import org.apache.pdfbox.pdmodel.PDDocument;

public class Main {

public static void main(String[] args)throws IOException {
//Creating PDF document object
PDDocument doc = new PDDocument();

//Saving the document
doc.save("/eclipse-workspace/blank.pdf");

System.out.println("PDF created");

//Closing the document
doc.close();
}
}

Working with MetaData

import java.io.IOException;   
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
import org.apache.pdfbox.pdmodel.PDPage;

public class DocumentProperties{
public static void main(String[] args)throws IOException {

//Creating PDF document object
PDDocument doc = new PDDocument();

//Creating a blank page
PDPage blankPage = new PDPage();

//Adding the blank page to the document
doc.addPage( blankPage );

//Creating the PDDocumentInformation object
PDDocumentInformation pdd = doc.getDocumentInformation();

//Setting the author of the document
pdd.setAuthor("Zeeshan Wazir");

// Setting the title of the document
pdd.setTitle("Sample Document");

//Setting the creator of the document
pdd.setCreator("Zeeshan Wazir");

//Setting the subject of the document
pdd.setSubject("PDF Example");

//Setting the created date of the document
Calendar date = new GregorianCalendar();
date.set(2018, 5, 7);
pdd.setCreationDate(date);

//Setting the modified date of the document
date.set(2018, 6, 5);
pdd.setModificationDate(date);

//Setting keywords for the document
pdd.setKeywords("Java, example, my pdf");

//Setting Producer for the document
pdd.setProducer("JavaTpoint.com");

//Saving the document
doc.save("/eclipse-workspace/blank.pdf");

System.out.println("Properties added successfully to a PDF document.");

//Closing the document
doc.close();
}
}

In the above code examples, you can see that its easy to work PDFs using Apache PDFBox Java PDF library. Overall its a good library and provides all necessary features to work on PDFs in Java.

License

Apache PDFBox is free and open source under the Apache License 2.0, which permits commercial use. The current releases are 3.0.8 and 2.0.37 (July 2026).

Summary

In this article I discussed 3 most popular PDF libraries in Java. All the libraries are fantastic to use and are best within their capabilities. IronPDF is a mature library and provides a wide range of PDF related functionalities. It is also available for .NET and built upon its success with full documented support.

iText is also a powerful library and provides a wide variety of components to work with PDF files in big projects. It is widely used in commercial software and provides a well documented API and technical support available.

Apache PDFBox is although an open source and free to use library but still it provides a variety of PDF related operations. Its fast and easy to use which helps developers integrate it their software applications and also help improve Apache PDFBox.

Choosing a right PDF library totally depends on one’s need and use. Personally, I prefer IronPDF: it covers HTML rendering, editing, security and accessibility in one API, and its perpetual licenses carry no recurring license fees (support and updates after the first year are optional and paid). iText’s commercial pricing is quote-based, so compare quotes for your own use case. If you need a free option, Apache PDFBox is a capable choice.

--

--

Zeeshan Wazir
Zeeshan Wazir