Java Library for PDF Documents Management

Open Source Java API to Create, Edit & Manipulate PDF Files from your own applications.

 

OpenPDF is an open-source PDF library for Java developers. It allows creating & modifying PDF files from Java apps without any external dependencies.  OpenPDF is licensed with an LGPL and MPL license & is a fork of iText version 4.

PDF is one of the World’s favorite document formats and still very useful. OpenPDF API support several important features, such as creation and modification of PDF documents, the addition of images to PDF, insertion of new pages to an existing PDF file, creation of paragraphs, the addition of header and footers, creation of TOC, content editing and more.

Getting Started with OpenPDF

Java 8 or later is required to use the OpenPDF library. All Java versions from 8 to Java 12 have been tested to work. It will compile the Java sources and package the binary classes into jar packages by default.

OpenPDF Maven Dependency

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

Create & Edit PDF Files via Java API

OpenPDF provides the functionality for PDF document creation as well as modifications from Java applications. Software developers can easily create PDF documents with content & images. In order to create a new document, first of all, you need to create a document object and then create a writer that listen to the document and directs a PDF stream to file. Once the document is created you can easily add paragraphs, add new pages, insert images with ease.

Create PDF document - Java

// Intialize Document object
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("FileFormat.pdf"));
// Open document
document.open();
// Add pargraph
document.add(new Paragraph("FileFormat Developer Guide"));
// Close document
document.close();

Insert Images to PDF Documents via Java

OpenPDF allows Java programmers to insert images into PDF documents inside their own Java applications. Images always add more value to the piece of content. To insert an image, you need to provide an image name and location, then by calling the document object you can open the document and add the image on the desired page or location. Once done you just need to close the document in order to commit changes.

Add Image in PDF - Java

// Intialize Document object
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
// Open document
document.open();
Image jpg = Image.getInstance("sample.jpg");
document.add(jpg);
// Close document
document.close();

Add Lists to PDF Documents

OpenPDF API facilitates Java developers to add lists to PDF documents. You can create a list and then add list-items to PDF with ease. You can also pass a symbol for marking the list-items (Unicode character). You can also select a numbered or lettered list. There are also specialized classes for Roman letters and Greek letters.