MCPcopy Index your code
hub / github.com/LibrePDF/OpenPDF

github.com/LibrePDF/OpenPDF @3.0.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release 3.0.5 ↗ · + Follow
13,760 symbols 55,792 edges 1,384 files 7,397 documented · 54%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

OpenPDF is an open source Java library for PDF files

OpenPDF is an open-source Java library for creating, editing, rendering, and encrypting PDF documents, as well as generating PDFs from HTML. It is licensed under the LGPL and MPL open source licenses. We welcome contributions from other developers. Please feel free to submit pull-requests and bug reports to this GitHub repository.

Features

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.
  • PDF 2.0 support (ISO 32000-2).
  • Brotli stream compression (/BrotliDecode) for creating and reading PDF streams compressed with Brotli – see Brotli compression.

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

Get OpenPDF

Get the latest version of OpenPDF.

Maven Central

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>3.0.5</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. OpenPDF is the LGPL/MPL open source successor of iText, and is based on some forks of iText 4 svn tag.

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.

Openpdf-html and Openpdf-renderer are licensed with GNU Lesser General Public License 2.1 only.

Documentation


Openpdf-html – HTML to PDF

Openpdf-html: Generates PDFs directly from HTML/CSS content.
Ideal for creating styled reports, invoices, and documents from web templates.

Maven artifact: com.github.librepdf:openpdf-html


Openpdf-renderer – PDF Rendering

Openpdf-renderer: Renders PDF pages to images or displays them in Java webapp/Swing/JavaFX applications.
Useful for previews, thumbnails, or embedding PDFs in GUIs.

Maven artifact: com.github.librepdf:openpdf-renderer


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.

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-html is a fork of Flying Saucer, forked in june 2025, project started in 2004. openpdf-renderer is a fork of PDFRenderer, porject started by Sun Labs in 2007. OpenPDF-core is a fork of iText, forked in October 2016, iText started in 2000.

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

Android

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

Contributing

We welcome contributions from other developers. 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". Knowing 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 (and later) 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.

OpenPDF Java package name change from com.lowagie to org.openpdf

The OpenPDF 3.0 version uses the new org.openpdf package name.

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>

Brotli4j

Brotli4j is a required dependency for Brotli stream compression support. https://github.com/hyperxpro/Brotli4j/

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

Brotli compression

OpenPDF can read and write PDF streams compressed with Brotli — exposed in the PDF as the /BrotliDecode filter, which is being standardised for PDF 2.0 (ISO 32000-2) through ISO/TS 32001. The codec is backed by brotli4j (a required dependency, with native binaries shipped for Linux / macOS / Windows on x86_64 and aarch64).

Enable Brotli for the page content streams produced by a writer:

PdfWriter writer = PdfWriter.getInstance(document, out);
writer.

setUseBrotliCompression(true);    // /BrotliDecode instead of /FlateDecode

…or globally for every subsequently-created PdfWriter:

Document.useBrotliCompression =true;

Reading is fully transparent: PdfReader.getStreamBytes(...) and PdfReader.getPageContent(...) decode /BrotliDecode automatically, so OpenPDF opens Brotli-compressed PDFs (e.g. those produced by AutoCAD's pdfplot11.hdi) without any extra configuration. The raw codec is available as org.openpdf.text.pdf.codec.BrotliFilter (encode / decode).

Default compression remains /FlateDecode for compatibility with older PDF readers that do not yet implement ISO/TS 32001.

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.

Extension points exported contracts — how you extend this code

OutputStreamResource (Interface)
An object that implements this interface is a resource that can be written to an OutputStream. [8 implementers]
pdf-swing/src/main/java/org/openpdf/rups/io/OutputStreamResource.java
Styleable (Interface)
All objects appearing the layout tree must implement this interface. It can roughly be thought of as a styled element ( [6 …
openpdf-html/src/main/java/org/openpdf/layout/Styleable.java
TextElementArray (Interface)
Interface for a text element to which other objects can be added. @see Phrase @see Paragraph @see Section @see ListItem [41 …
openpdf-core/src/main/java/org/openpdf/text/TextElementArray.java
PostScriptOperation (Interface)
(no doc) [84 implementers]
openpdf-renderer/src/main/java/org/openpdf/renderer/function/postscript/operation/PostScriptOperation.java
Example (Interface)
(no doc) [25 implementers]
pdf-toolbox/src/test/java/org/openpdf/examples/glyphlayout/RunGlyphLayoutExamplesMultithreading.java
JTableAutoModelInterface (Interface)
Tables that contain the information necessary for creating their model should implement this interface, so that they can [10 …
pdf-swing/src/main/java/org/openpdf/rups/view/models/JTableAutoModelInterface.java
InlinePaintable (Interface)
An interface which indicates that a box is able to paint itself in an inline context. This includes lines and laid out [6 …
openpdf-html/src/main/java/org/openpdf/layout/InlinePaintable.java
ElementListener (Interface)
A class that implements ElementListener will perform some actions when an Element is added. @ [34 implementers]
openpdf-core/src/main/java/org/openpdf/text/ElementListener.java

Core symbols most depended-on inside this repo

put
called by 2849
openpdf-core/src/main/java/org/openpdf/text/pdf/IntHashtable.java
add
called by 1166
openpdf-core/src/main/java/org/openpdf/text/ElementListener.java
get
called by 1072
openpdf-core/src/main/java/org/openpdf/text/pdf/parser/Matrix.java
append
called by 971
openpdf-core/src/main/java/org/openpdf/text/pdf/ByteBuffer.java
add
called by 727
openpdf-core/src/main/java/org/openpdf/text/Document.java
equals
called by 646
openpdf-core/src/main/java/org/openpdf/text/pdf/PdfName.java
put
called by 576
openpdf-core/src/main/java/org/openpdf/text/pdf/PdfDictionary.java
println
called by 539
pdf-swing/src/main/java/org/openpdf/rups/view/Console.java

Shape

Method 11,952
Class 1,688
Interface 91
Enum 29

Languages

Java100%
Kotlin1%

Modules by API surface

openpdf-html/src/main/java/org/openpdf/css/parser/property/PrimitivePropertyBuilders.java212 symbols
openpdf-core/src/main/java/org/openpdf/text/pdf/PdfWriter.java153 symbols
openpdf-html/src/main/java/org/openpdf/render/BlockBox.java142 symbols
openpdf-core/src/main/java/org/openpdf/text/pdf/PdfReader.java141 symbols
openpdf-core/src/main/java/org/openpdf/text/pdf/PdfContentByte.java141 symbols
openpdf-html/src/main/java/org/openpdf/css/style/CalculatedStyle.java139 symbols
openpdf-html/src/main/java/org/openpdf/render/Box.java129 symbols
openpdf-core/src/main/java/org/openpdf/text/pdf/PdfDocument.java116 symbols
openpdf-core/src/main/java/org/openpdf/text/Image.java107 symbols
openpdf-html/src/main/java/org/openpdf/newtable/TableBox.java105 symbols
openpdf-core/src/main/java/org/openpdf/text/pdf/parser/PdfContentStreamHandler.java100 symbols
openpdf-html/src/main/java/org/openpdf/pdf/ITextOutputDevice.java94 symbols

For agents

$ claude mcp add OpenPDF \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact