12

The title1 says it (nearly) all. To be more specific, I require

  • PDF generation
  • with basic formatting (tables and images)
  • usability in closed source commercial project
  • being free (as in beer) or nearly free

and prefer

  • easy of use
  • future-proof (no dead project)
  • ideally open source

Background: Tomorrow I'll generate some simple PDF and I'd be happy if it didn't take too much time and if the time spent was not wasted.


1 Taken from an equally named, but since long closed question on SO and I hope, this is a better place for it. The problem with the closed question is that the answers may be long obsolete. Even if not, there's no clear recommendation there.

  • Moving my deleted answer to comment as I can't see anything to improve further: Not literally Java libraries, but depending on context you may be able to shell out to standard libraries like Libtiff's tiff2pdf or ImageMagick. Also, do remember to consider whether PDF is really the format you want. Maybe a DjVu will be better? – Nemo Mar 19 '16 at 7:44
  • @Nemo Have you deleted your answer yourself? I consider your answer valid as PDF is a big pain and shelling out is pretty trivial. Unfortunately, PDF is the requirement. FYI, I use org.apache.pdfbox. I've spent more time with it than I wanted, but it did the job. – maaartinus Mar 19 '16 at 21:25
  • No, @Undo deleted it – Nemo Mar 20 '16 at 7:57
  • Another closed SO question: stackoverflow.com/questions/6625849/… – Vadzim Nov 21 '16 at 13:02
  • Here is a list of active opensource alternatives with comparisons and popularity estimates: java.libhunt.com/categories/438-pdf – Vadzim Nov 21 '16 at 13:06
11

iText

I am the CEO of the iText Group, the original author of iText as well as the author of two iText in Action books and the free ebook The Best iText Questions on StackOverflow.

The list you refer to mentions iText and with this answer, I want to confirm that iText still exists. It is available under an open source license (AGPL) as well as under a commercial license (which generates revenue that is used for further development).

Apart from being the CEO of the iText companies (with offices in Europe, the US and soon also in Singapore), I am also a member of the ISO committees that create the PDF standards. In less than a week, I am flying to San Jose (CA) to attend the meetings that will discuss ISO-32000-2 (the upcoming PDF 2.0 spec), ISO-19005 (PDF/A), ISO-14289 (PDF/UA),... I am also responsible for the ISO Adhoc committee for digital signatures (rewriting the part about digital signatures in ISO-32000-2).

At iText, we invest in further development, which isn't always the case for open source libraries that are offered with a free as in free beer license. For instance: both iText and PDFBox are a member of the PDF Association, but at the PDF Days in Cologne in 2014, PDFBox declared that they had no resources to invest in support for PDF 2.0. The project stands or falls with the existence of contributors who donate code. The business model used by iText generates money that allows us to pay developers.

Flying Saucer is a project that is built on top of iText, but it is not affiliated with the iText Group in any way. I don't think it is still supported, but I am not sure.

I didn't know about PDFClown until the developer of the tool teased me about a single feature that was available in PDFClown, but not in iText. I responded by implementing that feature myself. Based on the conversation, I assume that PDFClown is a one-man project.

I don't have much information on the other projects. One project that seems to be missing in the original list (but present in the comments and in another answer), is Apache FOP. Based on a survey that was organized by Black Duck Software on our behalf, Apache FOP seems to be running on many systems (it was the #2 after iText), but not that many developers were happy with it because of (1) the architecture that depends on XSL-FO, and (2) performance issues.

  • What about jasper reporting? Is this better than iText – Vinayak Dornala Jun 1 '16 at 15:58
  • 2
    @Vinayak Jasper Reports uses an old version of iText. Comparing Jasper Reports with iText is like comparing a car with its engine. – Bruno Lowagie Jun 1 '16 at 16:03
  • @BrunoLowagie can I get an open source licensed (AGPL) version of iText for free ? If, yes, can I able to use iText in my Android App and launch it in Google Play ? – Ragesh D Antony Oct 11 '17 at 13:06
  • 1
    @RageshDAntony Yes, you can get an AGPL version of iText for free. And yes, you can use it in an Android app for free, but only on condition that you offer that app as an open source application for free under the same conditions; that is: your app has to be 100% AGPL too. – Bruno Lowagie Oct 11 '17 at 20:35
  • 1
    I don't see how that would work @RageshDAntony because your customers would be paying you for a license to use your software that is not an AGPL license. The comparison with RH Enterprise Linux is wrong, because RH doesn't sell any licenses to use Linux. RH doesn't sell Linux "for cost". – Bruno Lowagie Oct 12 '17 at 6:28
5

LibreOffice

One indirect and free-of-cost route is to create or modify documents in LibreOffice using its Java API library. Then tell LibreOffice to create a PDF from that document.

Not simple, but doable. My team has done so in the past for a prototype (not in production). The LibreOffice API was confusing, with an odd design, not well documented, with only a few poor examples -- at least that was our experience.

However, I would strongly recommend considering use of iText if its cost can be made part of your budget. See the Answer by Bruno Lowagie.

3

jPDFWriter

Our software jPDFWriter is a Java library that can create PDF documents. jPDFWriter is free to use for commercial purposes, there are no license fees.

jPDFWriter can create PDF files in two ways:

  • PDF files can be created directly using jPDFWriter’s very simple API. Simply create a PDFDocument object, create as many PDFPage objects as necessary, draw strings, graphics or any other elements supported by Java Graphics2D to the pages and then save the document.

  • jPDFWriter also extends the standard Java PrinterJob so that you can create PDF files in the same way that you would print to a physical printer. This allows for reuse of existing printing code and for an application to decide, at runtime, whether to send the output to a printer or to a PDF file.

1

The Apache PDFBox® library is an open source Java tool for working with PDF documents. This project allows creation of new PDF documents, manipulation of existing documents and the ability to extract content from documents.

Apache PDFBox is published under the Apache License v2.0.

Features:

  • Extract Unicode text from PDF files.
  • Split a single PDF into many files or merge multiple PDF files.
  • Extract data from PDF forms or fill a PDF form.
  • Validate PDF files against the PDF/A-1b standard.
  • Print a PDF file using the standard Java printing API.
  • Save PDFs as image files, such as PNG or JPEG.
  • Create a PDF from scratch, with embedded fonts and images.
  • Digitally sign PDF files.
  • 2
    This comment is mainly to help people who come across this answer in the future, but at time of writing, the PDFBox library does not do any sort of layout. E.g., no text columns, no text wrapping or justification, no tables. If you want any sort of layout, you will need to use a separate layout library. A couple of examples on github are github.com/ralfstuckert/pdfbox-layout and github.com/gingerdroids/BlockFrame – David Mar 13 '17 at 13:46
1

JODReports

JODReports is open source and drives OpenOffice or LibreOffice as a conversion engine. This means you can design templates in a word processor or spreadsheet program, manipulate them, then convert to various formats including PDF.

The JODReports project was last updated Aug 2013 so hard to know if that "dead".


iText detailed by Bruno's answer might be ideal - it's a great library.

0

OpenPDF

OpenPDF is a Java PDF library, forked from iText.

As of 2017, it seems to be actively maintained.

0

I am the author of Open Lowcode PDF, an additional layer over the free Apache PDBBox. The framework is open-source, and the first version was just released today on github. Feel free to have a look and provide feedback.

The framework aims at producing documents and forms as commonly produced by companies with a standard elegant layout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.