Desktop Java

Java PDF Libraries

Recently I had a task to select some Java PDF libraries for PDF generation. But it wasn’t a simple task. The first thing which came into my mind was iText. It’s well know Java library with good reputation. But… there is some stopper. iText version 5+ is released under the AGPL license. I.e. we have to pay money if we want to use iText in commercial product. I’ve created the next small checklist which covers project needs:

  1. liberal license
  2. support maximum amount of project features (e.g. absolute element positioning)
  3. good documentation
  4. huge amount of samples
  5. possibility to render HTML to PDF

I’ve reviewed the next libraries:

  • iText 5.0+ AGPL license
  • iText 4.2 MPL/LGPL licenses
  • PDF Box Apache License, Version 2.0
  • JPedal JPedal has a LGPL release to provide a full java PDF viewer under a LGPL license
  • FOP Apache License, Version 2.0
  • gnujpdf LGPL License
  • PJX GPLv2 License
  • PDFjet Strange Open Source license model
  • jPod BSD License
  • PDF Renderer Maintaining is not active

iText review

  • iText 2.1.7: the latest official release under the MPL & LGPL license;
  • iText 4.2.0: the latest unofficial release under the MPL & LGPL license;
  • iText 5.0.0 and higher: released under the AGPL license.

Notes about iText 5.0+ vs iText 4.2 Beginning with iText version 5.0 the developers have moved to the AGPL to improve their ability to sell commercial licenses. .. To assist those desiring to stick with the old license was made the final MPL/LGPL version more easily available and forked on github.

Apache™ FOP

Apache™ FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application that reads a formatting object (FO) tree and renders the resulting pages to a specified output. This lib doesn’t have enough flexibility for absolute page element positioning. But, it might be really valuable as content convertor.

Apache PDFBox

Very interesting project. It has very impressive amount of features. And most important it’s in active development.

Summary

I’ve selected iText v.4.2 which has acceptable license and huge community. But the most important feature it’s a very good documentation (actually it’s a book iText in Action — 2nd Edition), tons of samples. Almost all samples for iText v.5 can be easily applied to iText v.4.2. Other libraries have not so much samples/demos. And for quick start it’s very important.
Here is maven dependency info:

com.lowagie
    itext
    4.2.0

PDFBox is selected as backup library. I.e. I will use it when iText has some limitations.

Resources

 

Reference: Java PDF Libraries from our JCG partner Orest Ivasiv at the Knowledge Is Everything blog.

Orest Ivasiv

Passionate software engineer interested in different programming languages, pragmatic approaches and performance boost practices.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

11 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Sean Loughran
Sean Loughran
10 years ago

I can’t say enough good things about iText. I’ve been using it for years to push the boundaries of PDFs and it hasn’t failed me yet. And as you said, iText In Action v2 is an amazing book!

jroom36
jroom36
10 years ago

You also should consider JODConverter(http://code.google.com/p/jodconverter/). It is abstract working with common task for document processing via OpenOffice: conversation, running/stopping, process restarting of Office copy.

Graham
10 years ago

You might like to also consider Docmosis. They have a Java PDF Library.

It uses a templating solution to handle the construction of a document/report. The templates can be created using common word processing packages like Microsoft Word.

http://www.docmosis.com

Orest
10 years ago
Reply to  Graham

nice, but it’s not free :(

cd
cd
10 years ago

Two libraries to look at.
1. Flying Saucer – https://code.google.com/p/flying-saucer/
2. Docx4j – http://www.docx4java.org/trac/docx4j

David Zondray
David Zondray
10 years ago

I think Aspose.Pdf is another one you must consider: http://www.aspose.com/java/pdf-component.aspx

Orest
10 years ago
Reply to  David Zondray

nice, but it’s not free :(

Ron
Ron
8 years ago
Reply to  David Zondray

In my 32 years as a software engineer, I’ve never experienced a worse POC than what I experienced with Aspose. The documentation and examples are horrendous… at least for their Java API. I could give you an arm’s length list of documentation errors and miscues that I found while trying to work my way through a POC, but I’ve already wasted enough time on Aspose.

Met
Met
8 years ago
Reply to  Ron

You are correct. Aspose is really a worst Java API for PDF. It have really worst performance issue than other APIs like iText. I’ll never suggest anyone Aspose PDF API.

tuhina
tuhina
9 years ago

great!

Leila Holmann
9 years ago

Qoppa has a suite of Java PDF libraries that are commercial but worth mentioning for those who don’t find what they need in the open source products mentioned in this article. Supported functions include rendering and printing, assembling, form filling, conversion to and from images, securing, digital signing, optimizing, etc… Thanks!

Back to top button