Convert Figma logo to code with AI

LibrePDF logoOpenPDF

OpenPDF is a free Java library for creating and editing PDF files, with a LGPL and MPL open source license. OpenPDF is based on a fork of iText. We welcome contributions from other developers. Please feel free to submit pull-requests and bugreports to this GitHub repository.

3,897
652
3,897
146

Top Related Projects

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!

iText for Java represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high and low-level programming capabilities and the ability to create, edit and enhance PDF documents, iText can be a boon to nearly every workflow.

JasperReportsĀ® - Free Java Reporting Library

2,857

Mirror of Apache PDFBox

JODConverter automates document conversions using LibreOffice or Apache OpenOffice.

2,401

Simple Logging Facade for Java

Quick Overview

OpenPDF is an open-source Java library for creating and editing PDF files. It's a fork of the iText project (version 4.2.0) and is maintained by the LibrePDF community. OpenPDF aims to provide a free, open-source alternative for PDF manipulation in Java applications.

Pros

  • Free and open-source, with a more permissive license than iText
  • Actively maintained and regularly updated
  • Compatible with existing iText 4.2.0 code, making migration easier
  • Supports a wide range of PDF manipulation tasks

Cons

  • Not as feature-rich as some commercial PDF libraries
  • Documentation can be limited compared to more established alternatives
  • May have compatibility issues with newer PDF standards
  • Performance might be slower for some operations compared to commercial alternatives

Code Examples

  1. Creating a simple PDF document:
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("simple.pdf"));
document.open();
document.add(new Paragraph("Hello, OpenPDF!"));
document.close();
  1. Adding an image to a PDF:
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("image.pdf"));
document.open();
Image img = Image.getInstance("path/to/image.jpg");
document.add(img);
document.close();
  1. Creating a table in a PDF:
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("table.pdf"));
document.open();
PdfPTable table = new PdfPTable(3);
table.addCell("Cell 1");
table.addCell("Cell 2");
table.addCell("Cell 3");
document.add(table);
document.close();

Getting Started

To use OpenPDF in your Java project, add the following dependency to your Maven pom.xml file:

<dependency>
    <groupId>com.github.librepdf</groupId>
    <artifactId>openpdf</artifactId>
    <version>1.3.30</version>
</dependency>

For Gradle, add this to your build.gradle file:

implementation 'com.github.librepdf:openpdf:1.3.30'

After adding the dependency, you can start using OpenPDF in your Java code by importing the necessary classes from the com.lowagie.text package.

Competitor Comparisons

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!

Pros of openhtmltopdf

  • Supports HTML and CSS rendering, allowing for more flexible and modern document creation
  • Actively maintained with regular updates and improvements
  • Offers better support for complex layouts and responsive design

Cons of openhtmltopdf

  • May have a steeper learning curve for users familiar with traditional PDF libraries
  • Potentially larger file size and resource usage due to HTML rendering engine
  • Some advanced PDF features might require additional configuration or plugins

Code Comparison

openhtmltopdf:

PdfRendererBuilder builder = new PdfRendererBuilder();
builder.withUri("https://example.com");
builder.toStream(outputStream);
builder.run();

openpdf:

Document document = new Document();
PdfWriter.getInstance(document, outputStream);
document.open();
document.add(new Paragraph("Hello, World!"));
document.close();

The code comparison shows that openhtmltopdf uses a builder pattern to configure and render HTML content, while openpdf uses a more traditional approach of creating a document and adding elements directly. openhtmltopdf's method allows for rendering existing HTML pages, while openpdf requires manual content creation within the code.

Both libraries have their strengths, with openhtmltopdf offering more flexibility for web-based content and openpdf providing a simpler approach for basic PDF generation. The choice between them depends on the specific requirements of your project and the type of content you need to generate.

iText for Java represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high and low-level programming capabilities and the ability to create, edit and enhance PDF documents, iText can be a boon to nearly every workflow.

Pros of itext-java

  • More comprehensive feature set, including advanced PDF manipulation capabilities
  • Better performance for large-scale PDF generation and processing
  • Extensive documentation and community support

Cons of itext-java

  • Commercial licensing required for many use cases
  • Steeper learning curve due to more complex API
  • Larger library size, which may impact application size

Code Comparison

openpdf example:

PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
document.open();
document.add(new Paragraph("Hello, OpenPDF!"));
document.close();

itext-java example:

PdfWriter writer = new PdfWriter(new FileOutputStream("output.pdf"));
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
document.add(new Paragraph("Hello, iText!"));
document.close();

Both libraries offer similar basic functionality for creating PDFs, but itext-java provides more advanced features and flexibility in document creation and manipulation. openpdf is generally simpler to use for basic tasks, while itext-java offers more power and control at the cost of complexity. The choice between the two depends on the specific requirements of your project, budget constraints, and the level of PDF manipulation needed.

JasperReportsĀ® - Free Java Reporting Library

Pros of JasperReports

  • More comprehensive reporting solution with advanced features like charting, subreports, and crosstabs
  • Supports multiple output formats including PDF, HTML, XLS, CSV, and XML
  • Offers a visual report designer (iReport) for easier report creation

Cons of JasperReports

  • Steeper learning curve due to its extensive feature set
  • Larger library size and potential performance overhead for simpler PDF generation tasks
  • Commercial licensing for some advanced features and support

Code Comparison

JasperReports:

JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, outputPath);

OpenPDF:

Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(outputPath));
document.open();
document.add(new Paragraph("Hello, World!"));
document.close();

The code comparison shows that JasperReports requires more setup and configuration for report generation, while OpenPDF offers a simpler approach for basic PDF creation. JasperReports is better suited for complex reporting needs, whereas OpenPDF is more lightweight and straightforward for simple PDF generation tasks.

2,857

Mirror of Apache PDFBox

Pros of PDFBox

  • More comprehensive feature set, including PDF creation, manipulation, and extraction
  • Larger and more active community, resulting in frequent updates and better support
  • Better documentation and extensive examples for various use cases

Cons of PDFBox

  • Larger library size, which may impact application size and load times
  • Steeper learning curve due to its extensive API and feature set
  • May be overkill for simple PDF-related tasks

Code Comparison

PDFBox example (creating a simple PDF):

PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
contentStream.setFont(PDType1Font.HELVETICA, 12);
contentStream.newLineAtOffset(100, 700);
contentStream.showText("Hello, World!");
contentStream.endText();
contentStream.close();
document.save("example.pdf");
document.close();

OpenPDF example (creating a simple PDF):

Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("example.pdf"));
document.open();
document.add(new Paragraph("Hello, World!"));
document.close();

OpenPDF offers a simpler API for basic PDF creation, while PDFBox provides more granular control over PDF elements and structure.

JODConverter automates document conversions using LibreOffice or Apache OpenOffice.

Pros of jodconverter

  • Supports a wide range of document formats, including Microsoft Office and OpenOffice
  • Provides a flexible API for document conversion and manipulation
  • Integrates well with LibreOffice for high-quality conversions

Cons of jodconverter

  • Requires LibreOffice or OpenOffice to be installed on the system
  • May have higher resource usage due to its dependency on external office suites
  • Can be more complex to set up and configure compared to simpler PDF libraries

Code Comparison

jodconverter:

JodConverter.convert(inputFile).to(outputFile).execute();

openpdf:

PdfReader reader = new PdfReader(inputFile);
PdfWriter writer = new PdfWriter(outputFile);
new PdfDocument(reader, writer).close();

jodconverter offers a more straightforward API for document conversion, while openpdf provides lower-level PDF manipulation capabilities. jodconverter is better suited for converting between various document formats, whereas openpdf excels in PDF-specific operations and generation.

2,401

Simple Logging Facade for Java

Pros of slf4j

  • Widely adopted logging facade with extensive ecosystem support
  • Allows switching between different logging implementations without code changes
  • Simple API with minimal overhead

Cons of slf4j

  • Not a full PDF library; focused solely on logging
  • Requires additional dependencies for actual logging implementation
  • Less feature-rich compared to openpdf's PDF capabilities

Code Comparison

slf4j:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Logger logger = LoggerFactory.getLogger(MyClass.class);
logger.info("This is a log message");

openpdf:

import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
document.open();
document.add(new Paragraph("Hello, PDF!"));
document.close();

Summary

slf4j is a logging facade that provides flexibility in choosing logging implementations, while openpdf is a library for creating and manipulating PDF documents. They serve different purposes and are not direct competitors. slf4j excels in providing a unified logging interface, while openpdf offers specific PDF-related functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

OpenPDF is an open source Java library for PDF files

OpenPDF is a Java library for creating and editing PDF files with a LGPL and MPL open source license. OpenPDF is the LGPL/MPL open source successor of iText, and is based on some forks of iText 4 svn tag. OpenPDF-html allows making PDF files from HTML. We welcome contributions from other developers. Please feel free to submit pull-requests and bugreports to this GitHub repository.

Maven Central CI License (LGPL version 2.1) License (MPL) Codacy Badge Codacy Badge CodeQL Quality Gate Status CodeFactor Join the chat at https://gitter.im/LibrePDF/OpenPDF Java 17 Java 21 Java 24 Kotlin

OpenPDF version 2.2.4 released 2025-07-01

Get version 2.2.4 here: https://github.com/LibrePDF/OpenPDF/releases/tag/2.2.4

Other versions

Features

Some of the features of OpenPDF include:

  • Openpdf Creating PDFs: You can use OpenPDF to create new PDF documents from scratch.
  • Manipulating Existing PDFs: OpenPDF allows you to modify existing PDF documents by adding or removing pages, modifying text, and more.
  • Openpdf-html Create PDF files from HTML, using OpenPDF-html which is a fork of Flying Saucer.
  • Openpdf-renderer Render PDF files as images using openpdf-render.
  • Openpdf-kotlin Kotlin module for easy creation of PDF files using Kotlin.
  • Text and Font Support: You can add text to PDF documents using various fonts and styles, and extract text from PDF files.
  • Graphics and Images: OpenPDF supports the addition of images and graphics to PDF files.
  • Table Support: The library facilitates the creation of tables in PDF documents.
  • Encryption: You can encrypt PDF documents for security purposes.
  • Page Layout: OpenPDF allows you to set the page size, orientation, and other layout properties.

Use OpenPDF as Maven dependency

Add this to your pom.xml file to use the latest version of OpenPDF:


<dependency>
  <groupId>com.github.librepdf</groupId>
  <artifactId>openpdf</artifactId>
  <version>2.2.4</version>
</dependency>

License

OpenPDF uses dual licensing: when using the library, you may choose either Mozilla Public License Version 2.0 or GNU Lesser General Public License 2.1.

The SPDX license identifier for OpenPDF licensing is MPL-2.0 OR LGPL-2.1+

GNU Lesser General Public License (LGPL), Version 2.1

For a short explanation see https://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License

Mozilla Public License Version 2.0

For a short explanation see https://en.wikipedia.org/wiki/Mozilla_Public_License

You can find also a nice explanation of these licenses under https://itsfoss.com/open-source-licenses-explained/

We want OpenPDF to consist of source code which is consistently licensed with the LGPL and MPL licences only. This also means that any new contributions to the project must have a dual LGPL and MPL license only.

Documentation

Background

OpenPDF is open source software with a LGPL and MPL license. It is a fork of iText version 4, more specifically iText svn tag 4.2.0, which was hosted publicly on sourceforge with LGPL and MPL license headers in the source code, and LGPL and MPL license documents in the svn repository. Beginning with version 5.0 of iText, the developers have moved to the AGPL to improve their ability to sell commercial licenses.

OpenPDF ancestors in GitHub (in fork order):

  1. @rtfarte / OpenPDF - parent of LibrePDF/OpenPDF
  2. @kulatamicuda / iText-4.2.0
  3. @daviddurand / iText-4.2.0
  4. @ymasory / iText-4.2.0 - original parent on GitHub

Security Notice

It is the responsibility of the application developer to ensure that all input passed into OpenPDF is trusted, sanitized, and safe. OpenPDF does not perform input validation or enforce sandboxing. For important security guidelines and common risks, please read our Security Policy.

Android

OpenPDF can be used with Android, more info here: Android-support

Contributing

Release the hounds! Please send all pull requests. Make sure that your contributions can be released with a dual LGPL and MPL license. In particular, pull requests to the OpenPDF project must only contain code that you have written yourself. GPL or AGPL licensed code will not be acceptable.

To contribute code to the OpenPDF project, your GitHub account must contain your real name, so that we can verify your identity. This is to ensure the trust, security and integrity of the OpenPDF project, and to prevent security incidents such as the "XZ Utils backdoor". Knowning the real name of the contributors will also identify and prevent conflict of interests.

More details: Contributing

Coding Style

  • Code indentation style is 4 spaces. Maximum line length is 120 characters.
  • Generally try to preserve the coding style in the file you are modifying.

Dependencies

Required Dependencies

We have now different versions of OpenPDF, and they require different versions of Java:

  • The 2.1.x Branch requires Java 21 or later.
  • The 2.0.x Branch requires Java 17 or later.
  • The 1.4.x Branch requires Java 11 or later.
  • The 1.3.x Branch requires Java 8 or later.

UTF-8 Fonts

As of 1.3.21 the UTF-8 Liberation fonts moved to its own module, to reduce the size of the OpenPDF jar. If you want to use the bundled UTF-8 fonts, please add the following dependency to your project and use the class org.librepdf.openpdf.fonts.Liberation.


<dependency>
  <groupId>com.github.librepdf</groupId>
  <artifactId>openpdf-fonts-extra</artifactId>
  <version>${openpdf.version}</version>
</dependency>

Supporting complex glyph substitution/ Ligature substitution

OpenPDF supports glyph substitution which is required for correct rendering of fonts ligature substitution requirements. FOP dependency is required to enable this feature. Refer following wiki for details: wiki

Supporting OpenType layout, glyph positioning, reordering and substitution

OpenPDF supports OpenType layout, glyph positioning, reordering and substitution which is e.g. required for correct positioning of accents, the rendering of non-Latin and right-to-left scripts. OpenPDF supports DIN 91379. See: wiki

Optional

  • BouncyCastle (BouncyCastle is used to sign PDF files, so it's a recommended dependency)
    • Provider (org.bouncycastle:bcprov-jdk18on or org.bouncycastle:bcprov-ext-jdk18on depending on which algorithm you are using)
    • PKIX/CMS (org.bouncycastle:bcpkix-jdk18on)
  • Apache FOP (org.apache.xmlgraphics:fop)
  • Please refer to our pom.xml to see what version is needed.

Credits

Please see Contributors.md.