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,494
581
3,494
136

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,609

Mirror of Apache PDFBox

JODConverter automates document conversions using LibreOffice or Apache OpenOffice.

2,319

Simple Logging Facade for Java

Quick Overview

OpenPDF is an open-source Java library for creating and editing PDF files. It is a fork of the iText project, maintained by the LibrePDF community, and aims to provide a free and open 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-based code, making migration easier
  • Supports a wide range of PDF manipulation tasks, including creation, editing, and form filling

Cons

  • May lack some advanced features found in commercial PDF libraries
  • Documentation can be limited compared to more established alternatives
  • Performance might be slower for certain operations compared to commercial solutions
  • Limited support for newer PDF features and standards

Code Examples

Creating a simple PDF document:

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("example.pdf"));
document.open();
document.add(new Paragraph("Hello, OpenPDF!"));
document.close();

Adding a table to a PDF:

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

Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("table_example.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();

Filling a PDF form:

import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.AcroFields;

PdfReader reader = new PdfReader("form_template.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("filled_form.pdf"));

AcroFields form = stamper.getAcroFields();
form.setField("name", "John Doe");
form.setField("email", "john@example.com");

stamper.close();
reader.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 and com.lowagie.text.pdf packages.

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

  • Better support for modern CSS and HTML5 features
  • More accurate rendering of complex layouts and designs
  • Active development with frequent updates and bug fixes

Cons of openhtmltopdf

  • Slower performance for large documents or high-volume processing
  • Larger file size and memory footprint
  • Steeper learning curve for advanced customization

Code Comparison

OpenPDF:

PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
document.open();
XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream("input.html"));
document.close();

openhtmltopdf:

PdfRendererBuilder builder = new PdfRendererBuilder();
builder.withUri("input.html");
builder.toStream(new FileOutputStream("output.pdf"));
builder.run();

Both libraries offer straightforward ways to convert HTML to PDF, but openhtmltopdf provides more modern and flexible options for handling complex layouts and styles. OpenPDF, on the other hand, is generally faster and more lightweight, making it suitable for simpler conversions or high-volume processing tasks.

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

  • Stricter licensing terms (AGPL or commercial license required for many use cases)
  • Steeper learning curve due to more complex API
  • Higher resource consumption for simple PDF tasks

Code Comparison

OpenPDF example:

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

itext-java example:

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

Both libraries offer similar basic functionality for creating simple PDF documents. However, itext-java provides more advanced features and customization options for complex PDF manipulation tasks, while OpenPDF focuses on simplicity and ease of use for basic PDF generation.

JasperReportsĀ® - Free Java Reporting Library

Pros of JasperReports

  • More comprehensive reporting solution with advanced features like charting and cross-tabulation
  • Supports multiple output formats including PDF, HTML, Excel, and CSV
  • Offers a visual report designer (Jaspersoft Studio) for easier report creation

Cons of JasperReports

  • Steeper learning curve due to its extensive feature set
  • Larger footprint and potentially slower performance for simple PDF generation tasks
  • Commercial licensing for some advanced features and support

Code Comparison

OpenPDF (simple PDF generation):

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

JasperReports (basic report generation):

JasperReport jasperReport = JasperCompileManager.compileReport("report.jrxml");
Map<String, Object> parameters = new HashMap<>();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, "output.pdf");

Both libraries serve different purposes. OpenPDF is lightweight and focused on PDF manipulation, while JasperReports is a full-fledged reporting solution with broader capabilities but increased complexity.

2,609

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

Cons of PDFBox

  • Steeper learning curve due to its extensive API
  • Larger library size, which may impact application size and performance

Code Comparison

OpenPDF:

PdfReader reader = new PdfReader("input.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("output.pdf"));
stamper.close();
reader.close();

PDFBox:

PDDocument document = PDDocument.load(new File("input.pdf"));
document.save("output.pdf");
document.close();

Both libraries offer similar functionality for basic PDF operations, but PDFBox generally requires fewer lines of code for simple tasks. However, OpenPDF may be more intuitive for developers familiar with iText.

OpenPDF is a fork of iText, focusing on maintaining a free and open-source PDF library. It's lighter and easier to use for basic PDF operations. PDFBox, being an Apache project, offers a more comprehensive set of features and better long-term support, but may be overkill for simple use cases.

Choose OpenPDF for quick, straightforward PDF tasks, and PDFBox for more complex PDF manipulation and processing needs.

JODConverter automates document conversions using LibreOffice or Apache OpenOffice.

Pros of JODConverter

  • Supports a wide range of document formats, including ODT, DOC, DOCX, PDF, and more
  • Provides a high-level API for easy integration into Java applications
  • Utilizes LibreOffice or OpenOffice for document conversion, ensuring high-quality output

Cons of JODConverter

  • Requires LibreOffice or OpenOffice to be installed on the system
  • May have slower performance compared to native PDF libraries for simple PDF operations
  • Limited to document conversion tasks, lacking specific PDF manipulation features

Code Comparison

JODConverter (converting a document to PDF):

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

OpenPDF (creating a simple PDF):

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

JODConverter focuses on document conversion across various formats, while OpenPDF specializes in PDF creation and manipulation. JODConverter offers broader format support but requires external dependencies, whereas OpenPDF provides more direct control over PDF content but is limited to PDF-specific operations.

2,319

Simple Logging Facade for Java

Pros of SLF4J

  • Widely adopted logging facade with extensive ecosystem support
  • Allows for easy switching between different logging implementations
  • Provides a simple and intuitive API for logging

Cons of SLF4J

  • Not a full logging implementation, requires additional dependencies
  • Limited built-in formatting options 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("This is a PDF document"));
document.close();

Summary

SLF4J is a logging facade for Java applications, while OpenPDF is a library for creating and manipulating PDF documents. They serve different purposes and are not directly comparable. SLF4J excels in providing a unified logging interface, while OpenPDF offers robust PDF generation capabilities. The choice between them depends on the specific requirements of your project.

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. 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

OpenPDF version 2.0.3 released 2024-08-07

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

Please note: Repositories like Maven Central and others may take a few days to update.

Other versions

Features

Some of the features of OpenPDF include:

  • 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.
  • 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.0.3</version>
</dependency>

License

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

Projects using OpenPDF

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.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.
  • Some versions of 1.3 where release with Java 11 as minimum requirement, but we have reverted this to Java 8 as minimum requirement.
  • OpenPDF versions 2.0.x: We are working on modernizing the OpenPDF library for Java 17+.

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.