PRODUCT COMPARISONS A Comparison between IronPDF for Java and Apache PDFBox ByDarrius Serrant January 14, 2023 Updated June 22, 2025 Share: This article will cover the following two of the most popular libraries used in Java to work with PDF files:IronPDFApache PDFBoxNow which library should we use? In this article, I'll compare both libraries' core functionality to allow you to make a decision about which one is best for your production environment. View the IronPDF YouTube Playlist How to Convert HTML to PDF in Apache PDFBOX Install Java library to convert HTML to PDF Create new document and page instance with Apache PDFBox Create a new PDPageContentStream with the document and page as input Use the PDPageContentStream instance to configure and add content Export the PDF document with save method IronPDF The IronPDF library supports HTML to PDF Conversion for Java 8+, Kotlin, and Scala. This creator provides cross-platform support, i.e., Windows, Linux, or Cloud platforms. It is designed especially for Java, prioritizing accuracy, ease of use, and speed. IronPDF is developed to help software developers create, edit, and extract content from PDF documents. It is based on the success and popularity of IronPDF for .NET. Standout features of IronPDF include: Use HTML Assets HTML (5 and below), CSS (Screen & Print), images (JPG, PNG, GIF, TIFF, SVG, BMP), JavaScript (+ Render Delays) Fonts (Web & Icon) HTML to PDF HTML file/string to PDF document creation and manipulation URL to PDF Convert Images Image to new PDF documents PDF to Image Custom Paper Settings Custom Paper Size, Orientation & Rotation Margins (mm, inch & zero) Color & Grayscale, Resolution & JPEG Quality Additional Features Website & System Logins Custom User Agents and Proxies HTTP Headers Apache PDFBox library Apache PDFBox is an open-source Java library for working with PDF files. It allows one to generate, edit, and manipulate existing documents. It can also extract content from files. The library provides several utilities that are used to perform various operations on documents. Here are the standout features of Apache PDFBox. Extract Text Extract Unicode text from files. Split & Merge Split a single PDF into many files Merge multiple documents. Fill Forms Extract data from forms Fill a PDF form. Preflight Validate files against the PDF/A-1b standard. Print Print a PDF using the standard printing API. Save as Image Save PDFs as PNG, JPEG, or other image types. Create PDFs Develop a PDF from scratch with embedded fonts and images. Signing Digitally sign files. Overview The rest of the article goes as follows: IronPDF Installation Apache PDFBox Installation Create PDF Document Images to Document Encrypting Documents Licensing Conclusion Now, we will download and install the libraries to compare them and their powerful features. 1. IronPDF Installation Installing IronPDF for Java is simple. There are different ways of doing it. This section will demonstrate two of the most popular ways. 1.1. Download JAR and add the Library To download the IronPDF JAR file, visit the Maven website for IronPDF and download the latest version of IronPDF. Click the Downloads option and download the JAR. Download IronPDF JAR Once the JAR is downloaded, it's now time to install the library into our Maven project. You can use any IDE, but we will be using NetBeans. In the Projects section: Right-Click the Libraries folder and select the Add JAR/Folder option. Add IronPDF Library in Netbeans Move to the folder where you downloaded the JAR. Select the IronPDF JAR and click the Open button. Open IronPDF JAR 1.2. Install via Maven as a Dependency Another way of downloading and installing IronPDF is using Maven. You can simply add the dependency in the pom.xml or use NetBeans's Dependency tool to include it in your project. Add the Library Dependency in pom.xml Add the following dependency in your pom.xml: <dependencies> <dependency> <groupId>com.ironsoftware</groupId> <artifactId>ironpdf</artifactId> <version>YOUR_VERSION_HERE</version> </dependency> </dependencies> <dependencies> <dependency> <groupId>com.ironsoftware</groupId> <artifactId>ironpdf</artifactId> <version>YOUR_VERSION_HERE</version> </dependency> </dependencies> XML Add The Library using the Dependencies Feature Right-Click on dependencies Select Add Dependency and fill in the following details with the updated version Add IronPDF Dependency Now let's install Apache PDFBox. 2. Apache PDFBox Installation We can download and install PDFBox using the same methods as IronPDF. 2.1. Download JAR and Add the Library Manually To install PDFBox JAR, visit the official website and download the PDFBox library the latest version. After creating a project, in the project section: Right-Click the Libraries folder and select Add JAR/Folder option. Add Library Move to the folder where you downloaded the JAR. Select the PDFBox JAR and click the Open button. Open PDFBox JAR 2.2. Install via Maven as a Dependency Add Dependency in the pom.xml Copy the following code and paste it in the pom.xml. <dependencies> <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox-app</artifactId> <version>3.0.0-alpha3</version> </dependency> </dependencies> <dependencies> <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox-app</artifactId> <version>3.0.0-alpha3</version> </dependency> </dependencies> XML This will automatically download the PDFBox dependency and install it in the repository folder. It will now be ready to use. Add Dependency using the Dependencies Feature Right-Click on dependencies in the project section Select Add Dependency and fill in the following details with the updated version Add PDFBox Dependency 3. Create PDF Document 3.1. Using IronPDF IronPDF provides different methods for creating files. Let's have a look at two of the most important methods. Existing URL to PDF IronPDF makes it very simple to generate documents from HTML. The following code sample converts a web page's URL to a PDF. import com.ironsoftware.ironpdf.*; import java.nio.file.Paths; // Set the license key and log path License.setLicenseKey("YOUR-LICENSE-KEY"); Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log")); // Convert a URL to a PDF PdfDocument myPdf = PdfDocument.renderUrlAsPdf("https://ironpdf.com"); // Save the PDF document to a file myPdf.saveAs(Paths.get("url.pdf")); import com.ironsoftware.ironpdf.*; import java.nio.file.Paths; // Set the license key and log path License.setLicenseKey("YOUR-LICENSE-KEY"); Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log")); // Convert a URL to a PDF PdfDocument myPdf = PdfDocument.renderUrlAsPdf("https://ironpdf.com"); // Save the PDF document to a file myPdf.saveAs(Paths.get("url.pdf")); JAVA The output is the below URL that is well formatted and saved as follows: IronPDF URL Output HTML Input String to PDF The following sample code shows how an HTML string can be used to render a PDF in Java. You simply use an HTML string or document to convert it to new documents. import com.ironsoftware.ironpdf.*; import java.nio.file.Paths; // Set the license key and log path License.setLicenseKey("YOUR-LICENSE-KEY"); Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log")); // Convert an HTML string to a PDF PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!"); // Save the PDF document to a file myPdf.saveAs(Paths.get("html_saved.pdf")); import com.ironsoftware.ironpdf.*; import java.nio.file.Paths; // Set the license key and log path License.setLicenseKey("YOUR-LICENSE-KEY"); Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log")); // Convert an HTML string to a PDF PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!"); // Save the PDF document to a file myPdf.saveAs(Paths.get("html_saved.pdf")); JAVA The output is as follows: IronPDF HTML Output 3.2. Using Apache PDFBox PDFBox can also generate new PDF documents from different formats, but it cannot convert directly from URL or HTML string. The following code sample creates a document with some text: import org.apache.pdfbox.pdmodel.*; import org.apache.pdfbox.pdmodel.common.*; import org.apache.pdfbox.pdmodel.font.*; import org.apache.pdfbox.pdmodel.graphics.image.*; import org.apache.pdfbox.pdmodel.interactive.annotation.*; import org.apache.pdfbox.pdmodel.interactive.form.*; import java.io.IOException; public class PDFBoxExample { public static void main(String[] args) throws IOException { // Create a document object PDDocument document = new PDDocument(); // Add a blank page to the document PDPage blankPage = new PDPage(); document.addPage(blankPage); // Retrieve the page of the document PDPage paper = document.getPage(0); try (PDPageContentStream contentStream = new PDPageContentStream(document, paper)) { // Begin the content stream contentStream.beginText(); // Set the font to the content stream contentStream.setFont(PDType1Font.TIMES_ROMAN, 12); // Set the position for the line contentStream.newLineAtOffset(25, 700); String text = "This is the sample document and we are adding content to it."; // Add text in the form of a string contentStream.showText(text); // End the content stream contentStream.endText(); System.out.println("Content added"); // Save the document document.save("C:/PdfBox_Examples/my_doc.pdf"); System.out.println("PDF created"); } // Closing the document document.close(); } } import org.apache.pdfbox.pdmodel.*; import org.apache.pdfbox.pdmodel.common.*; import org.apache.pdfbox.pdmodel.font.*; import org.apache.pdfbox.pdmodel.graphics.image.*; import org.apache.pdfbox.pdmodel.interactive.annotation.*; import org.apache.pdfbox.pdmodel.interactive.form.*; import java.io.IOException; public class PDFBoxExample { public static void main(String[] args) throws IOException { // Create a document object PDDocument document = new PDDocument(); // Add a blank page to the document PDPage blankPage = new PDPage(); document.addPage(blankPage); // Retrieve the page of the document PDPage paper = document.getPage(0); try (PDPageContentStream contentStream = new PDPageContentStream(document, paper)) { // Begin the content stream contentStream.beginText(); // Set the font to the content stream contentStream.setFont(PDType1Font.TIMES_ROMAN, 12); // Set the position for the line contentStream.newLineAtOffset(25, 700); String text = "This is the sample document and we are adding content to it."; // Add text in the form of a string contentStream.showText(text); // End the content stream contentStream.endText(); System.out.println("Content added"); // Save the document document.save("C:/PdfBox_Examples/my_doc.pdf"); System.out.println("PDF created"); } // Closing the document document.close(); } } JAVA PDFBox Positioned Output However, if we remove contentStream.newLineAtOffset(25, 700); from the above code example and then run the project, it produces a PDF with output at the bottom of the page. This can be pretty annoying for some developers, as they have to adjust the text using (x,y) coordinates. y = 0 means that the text will appear at the bottom. PDFBox without Positioning Output 4. Images to Document 4.1. Using IronPDF IronPDF can easily convert multiple images to a single PDF. The code for adding multiple images to a single document goes as follows: import com.ironsoftware.ironpdf.*; import java.nio.file.*; import java.util.ArrayList; import java.util.List; // Reference to the directory containing the images that we desire to convert List<Path> images = new ArrayList<>(); images.add(Paths.get("imageA.png")); images.add(Paths.get("imageB.png")); images.add(Paths.get("imageC.png")); images.add(Paths.get("imageD.png")); images.add(Paths.get("imageE.png")); // Render all targeted images as PDF content and save them together in one document. PdfDocument merged = PdfDocument.fromImage(images); merged.saveAs(Paths.get("output.pdf")); import com.ironsoftware.ironpdf.*; import java.nio.file.*; import java.util.ArrayList; import java.util.List; // Reference to the directory containing the images that we desire to convert List<Path> images = new ArrayList<>(); images.add(Paths.get("imageA.png")); images.add(Paths.get("imageB.png")); images.add(Paths.get("imageC.png")); images.add(Paths.get("imageD.png")); images.add(Paths.get("imageE.png")); // Render all targeted images as PDF content and save them together in one document. PdfDocument merged = PdfDocument.fromImage(images); merged.saveAs(Paths.get("output.pdf")); JAVA IronPDF Images to Output 4.2. Using Apache PDFBox import org.apache.pdfbox.pdmodel.*; import org.apache.pdfbox.pdmodel.graphics.image.*; import java.io.IOException; import java.nio.file.*; import java.util.ArrayList; import java.util.List; public class ImageToPdf { public static void main(String[] args) { // Reference to the directory containing the images that we desire to convert Path imageDirectory = Paths.get("assets/images"); // Create an empty list to contain Paths to images from the directory. List<Path> imageFiles = new ArrayList<>(); PDDocument doc = new PDDocument(); // Use a DirectoryStream to populate the list with paths for each image in the directory that we want to convert try (DirectoryStream<Path> stream = Files.newDirectoryStream(imageDirectory, "*.{png,jpg}")) { for (Path entry : stream) { imageFiles.add(entry); } for (int i = 0; i < imageFiles.size(); i++) { // Add a Page PDPage blankPage = new PDPage(); doc.addPage(blankPage); PDPage page = doc.getPage(i); // Create PDImageXObject object PDImageXObject pdImage = PDImageXObject.createFromFile(imageFiles.get(i).toString(), doc); // Create the PDPageContentStream object PDPageContentStream contents = new PDPageContentStream(doc, page); // Drawing the image in the document contents.drawImage(pdImage, 0, 0); System.out.println("Image inserted"); // Closing the PDPageContentStream object contents.close(); } // Saving the document doc.save("C:/PdfBox_Examples/sample.pdf"); // Closing the document doc.close(); } catch (IOException exception) { throw new RuntimeException(String.format("Error converting images to PDF from directory: %s: %s", imageDirectory, exception.getMessage()), exception); } } } import org.apache.pdfbox.pdmodel.*; import org.apache.pdfbox.pdmodel.graphics.image.*; import java.io.IOException; import java.nio.file.*; import java.util.ArrayList; import java.util.List; public class ImageToPdf { public static void main(String[] args) { // Reference to the directory containing the images that we desire to convert Path imageDirectory = Paths.get("assets/images"); // Create an empty list to contain Paths to images from the directory. List<Path> imageFiles = new ArrayList<>(); PDDocument doc = new PDDocument(); // Use a DirectoryStream to populate the list with paths for each image in the directory that we want to convert try (DirectoryStream<Path> stream = Files.newDirectoryStream(imageDirectory, "*.{png,jpg}")) { for (Path entry : stream) { imageFiles.add(entry); } for (int i = 0; i < imageFiles.size(); i++) { // Add a Page PDPage blankPage = new PDPage(); doc.addPage(blankPage); PDPage page = doc.getPage(i); // Create PDImageXObject object PDImageXObject pdImage = PDImageXObject.createFromFile(imageFiles.get(i).toString(), doc); // Create the PDPageContentStream object PDPageContentStream contents = new PDPageContentStream(doc, page); // Drawing the image in the document contents.drawImage(pdImage, 0, 0); System.out.println("Image inserted"); // Closing the PDPageContentStream object contents.close(); } // Saving the document doc.save("C:/PdfBox_Examples/sample.pdf"); // Closing the document doc.close(); } catch (IOException exception) { throw new RuntimeException(String.format("Error converting images to PDF from directory: %s: %s", imageDirectory, exception.getMessage()), exception); } } } JAVA PDFBox Images to Output 5. Encrypting Documents 5.1. Using IronPDF The code for encrypting PDFs with a password in IronPDF is given below: import com.ironsoftware.ironpdf.*; import java.nio.file.Paths; // Open a document (or create a new one from HTML) PdfDocument pdf = PdfDocument.fromFile(Paths.get("assets/composite.pdf")); // Edit security settings SecurityOptions securityOptions = new SecurityOptions(); securityOptions.setOwnerPassword("top-secret"); securityOptions.setUserPassword("sharable"); // Change or set the document encryption password SecurityManager securityManager = pdf.getSecurity(); securityManager.setSecurityOptions(securityOptions); pdf.saveAs(Paths.get("assets/secured.pdf")); import com.ironsoftware.ironpdf.*; import java.nio.file.Paths; // Open a document (or create a new one from HTML) PdfDocument pdf = PdfDocument.fromFile(Paths.get("assets/composite.pdf")); // Edit security settings SecurityOptions securityOptions = new SecurityOptions(); securityOptions.setOwnerPassword("top-secret"); securityOptions.setUserPassword("sharable"); // Change or set the document encryption password SecurityManager securityManager = pdf.getSecurity(); securityManager.setSecurityOptions(securityOptions); pdf.saveAs(Paths.get("assets/secured.pdf")); JAVA 5.2. Using Apache PDFBox Apache PDFBox also provides document encryption to make the files more secure. You can also add additional information like metadata. The code goes as follows: import org.apache.pdfbox.pdmodel.*; import org.apache.pdfbox.pdmodel.encryption.*; import java.io.File; import java.io.IOException; public class PDFEncryption { public static void main(String[] args) throws IOException { // Load an existing document File file = new File("C:/PdfBox_Examples/sample.pdf"); PDDocument document = PDDocument.load(file); // Create access permission object AccessPermission ap = new AccessPermission(); // Create StandardProtectionPolicy object StandardProtectionPolicy spp = new StandardProtectionPolicy("1234", "1234", ap); // Setting the length of the encryption key spp.setEncryptionKeyLength(128); // Set the access permissions spp.setPermissions(ap); // Protect the document document.protect(spp); System.out.println("Document encrypted"); // Save the document document.save("C:/PdfBox_Examples/encrypted.pdf"); // Close the document document.close(); } } import org.apache.pdfbox.pdmodel.*; import org.apache.pdfbox.pdmodel.encryption.*; import java.io.File; import java.io.IOException; public class PDFEncryption { public static void main(String[] args) throws IOException { // Load an existing document File file = new File("C:/PdfBox_Examples/sample.pdf"); PDDocument document = PDDocument.load(file); // Create access permission object AccessPermission ap = new AccessPermission(); // Create StandardProtectionPolicy object StandardProtectionPolicy spp = new StandardProtectionPolicy("1234", "1234", ap); // Setting the length of the encryption key spp.setEncryptionKeyLength(128); // Set the access permissions spp.setPermissions(ap); // Protect the document document.protect(spp); System.out.println("Document encrypted"); // Save the document document.save("C:/PdfBox_Examples/encrypted.pdf"); // Close the document document.close(); } } JAVA 6. Pricing and Licensing IronPDF Pricing and Licensing IronPDF is free to use for developing simple PDF applications and can be licensed for commercial use at any time. IronPDF offers single project licenses, single developer licenses, licenses for agencies and multinational organizations, and SaaS and OEM redistribution licenses and support. All licenses are available with a free trial, a 30-day money-back guarantee, and one year of software support and upgrades. The Lite package is available for $749. There are absolutely no recurring fees with IronPDF products. More detailed information about software licensing is available on the product IronPDF licensing page. IronPDF Licensing Apache PDFBox Pricing and Licensing Apache PDFBox is freely available without any charges. It is free regardless of how it is used, whether for personal, for internal, or for commercial purposes. You can include the Apache License 2.0 (current version) from the Apache License 2.0 Text. To include the copy of the license, simply include it in your work. You can also attach the following notice as a comment at the top of your source code. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Conclusion In comparison, IronPDF has an upper hand over Apache PDFBox in both functionality and product support. It also provides SaaS and OEM support, which is a requirement in modern software development. However, the library is not free for commercial use like Apache PDFBox is. Companies with large software applications may require continual bug fixes and support from third-party vendors to resolve problems as they arise during software development. This is something that is lacking in many open-source solutions like Apache PDFBox, which relies on voluntary support from its community of developers to keep it maintained. In short, IronPDF is best used for business and market use, while Apache PDFBox is better suited for personal and non-commercial applications. There is also a free trial to test the functionality of IronPDF. Give it a try or buy IronPDF. You can now get all Iron Software products in the Iron Suite at a greatly reduced price. Visit this Iron Suite web page for more information about this amazing deal. Frequently Asked Questions What is this software library used for converting HTML to PDF? IronPDF is a library for Java that supports HTML to PDF conversion. It is designed for cross-platform use and prioritizes accuracy, ease of use, and speed. What is Apache PDFBox? Apache PDFBox is an open-source Java library used for working with PDF files, allowing you to generate, edit, manipulate, and extract content from PDF documents. How does this software library compare to Apache PDFBox? IronPDF offers more advanced features and support for commercial use, while Apache PDFBox is free and suitable for personal and non-commercial applications. Can this library convert URLs to PDF? Yes, IronPDF can convert a webpage URL to a PDF document, making it easy to generate PDFs from online content. Can Apache PDFBox convert HTML to PDF directly? No, Apache PDFBox cannot convert HTML directly to PDF. It requires additional steps to add content to a PDF. What are the standout features of this PDF software? IronPDF supports HTML and URL to PDF conversion, image conversion, custom paper settings, and additional features like system logins and custom user agents. What are the key features of Apache PDFBox? Apache PDFBox can extract text, split & merge documents, fill forms, validate files against PDF/A-1b, print PDFs, save as images, create PDFs from scratch, and digitally sign files. Is there a cost for using this library? IronPDF is free for developing simple PDF applications, but requires a license for commercial use. Various licensing options are available. What is the licensing model for Apache PDFBox? Apache PDFBox is free to use under the Apache License 2.0, which allows for personal, internal, and commercial use without charge. How can I install this PDF software in a Java project? IronPDF can be installed by downloading the JAR file from Maven or by adding it as a dependency in your project's pom.xml file. Darrius Serrant Chat with engineering team now Full Stack Software Engineer (WebOps) Darrius Serrant holds a Bachelor’s degree in Computer Science from the University of Miami and works as a Full Stack WebOps Marketing Engineer at Iron Software. Drawn to coding from a young age, he saw computing as both mysterious and accessible, making it the perfect medium for creativity and problem-solving.At Iron Software, Darrius enjoys creating new things and simplifying complex concepts to make them more understandable. As one of our resident developers, he has also volunteered to teach students, sharing his expertise with the next generation.For Darrius, his work is fulfilling because it is valued and has a real impact. A Comparison Between IronPDF for Java & Spire.PDF JavaA Comparison between IronPDF For Java and iTextPDF itext7 for Java