Compare these products for PDF generation with Java given requirements inside: iText, Apache PDFBox or FOP?

64,492

Solution 1

  1. iText; nowadays iText is a commercial library, the latest version is not for free anymore (a fork of an older version remains under MIT license: OpenPDF)
  2. FOP; I worked a lot with FOP. It's fairly resource intensive (Java > XML > XSLT > PDF) and complex PDFs become a nightmare ( may result in XSLTs with 20k+ LoC)
  3. PDFBox; it seems to be the best alternative although I did not work with it in large projects
  4. Did not check Flying Saucer yet

To conclude, I'd give PDFBox a try. Depending on your bar code requirements you may need to inline your barcode (font) into the PDF or distribute the font to your clients - take care of those issues.

Solution 2

I've done a project with Flying Saucer http://code.google.com/p/flying-saucer/ which is based on iText. It's free, easy to use, has great support for CSS, and has nice open source.

Solution 3

I think your criteria can be met with both iText and Apahce FOp but here you have some additional criteria:

  • licensing: FOP is based on Apache license and therefore "friendly" also for commercial use
  • flexbility: a low level API like iText is more flexible than high level FOP
  • Visual tools: there is one designer for FOP here.
  • Programing Model: iText is based on programming API while FOP requires a XSLFO template and less programming.
  • Proprietary vs standard. Apache FOP is based on a standard and therefore vendor independent, while iText is a proprietaRy API
  • Performace: It is said FOP is more computing intensive. it depends of course of what your target PDF files are. It was a never issue for me using FOP.

I would not use PDFBox, it is good for reading and modifying an existing PDF file but createing a file from scratch using PDFBox can be a lot of work.

Solution 4

I'm a bit biased (committer), but I suggest iText.

generating pdf documents based on predefined template (I can use either pdf forms or xsl-fo)

PDF forms: Check

being able to fill textual data

PDF Forms, check. You can also perform programmatic layout.

being able to fill graphical data (generated bar codes)

Check. Given a known location (which could be "the location of this particular annotation"), iText will draw a barcode for you given a symbology and value. You can deduce a list of supported symbologies from the constants listed here.

For this sort of thing, I use Button fields with an "Icon Only" appearance. The "icon" is some arbitrary PDF drawing instructions, or an image. iText's barcode stuff will create a PdfTemplate you can stuff into the button without too much trouble.

being able to alter pdf template in production environment without patching (recompiling)

If all your layout is baked into the PDF template, and your "barcode goes here" info isn't hard coded into the source, then you're golden.

generating pdf file to be saved in the database (as blob) and/or printed

A PDF is a PDF is a PDF. Heck, with some extra work on your part, you can use iText to build PDF/A files. "A" is for Archive.

open source/free

Open Source: Yes. v2.1.7 was the last version to use the MPL. Since 5.x, all iText releases have been under the AGPL. Yes, iText skipped from 2.1.7 to 5.0, in order to synchronize the version numbering between iText and iTextSharp.

Not exactly "little f" free, but the 2.1.7 version isn't that hard to come by. OTOH, it's orphan-ware, unmaintained. Be an informed consumer.

Solution 5

It depends how exactly you want to create the PDF as well. FOP works from XML, IText lets you create programmatically from Java.

Share:
64,492
topchef
Author by

topchef

My interests lie in predictive analytics and parallel processing with big data and its applications. Read more on technologies I use: novyden blog or read this when you are tired of everything stackoverflow has to offer.

Updated on July 09, 2022

Comments

  • topchef
    topchef almost 2 years

    There were questions on that but not recently and technology must have gone ahead since then.

    Requirements:

    • generating pdf documents based on predefined template (I can use either pdf forms or xsl-fo)
    • being able to fill textual data
    • being able to fill graphical data (generated bar codes)
    • being able to alter pdf template in production environment without patching (recompiling)
    • generating pdf file to be saved in the database (as blob) and/or printed
    • open source/free

    The options assumed are iText, PDFBox, FOP, anything else? What are recommendations based on the requirements above?

  • topchef
    topchef almost 13 years
    did you have to use graphical features similar to inserting barcodes into pdf?
  • Brian Hoover
    Brian Hoover almost 13 years
    Yes, it's just an img tag if you're converting HTML. We've created PDF documents with several thousand dynamically generated barcodes using Flying Saucer. It handled it perfectly.
  • topchef
    topchef almost 13 years
    with respect to barcode: I looked up how barcode4j handles it with FOP - it does it as not a font but an image. I guess I'll need another question on integrating barcodes into pdf...
  • topchef
    topchef almost 13 years
    Does flying saucer require license for itext? Is it free then?
  • Brian Hoover
    Brian Hoover almost 13 years
    I used it with the free version of iText and it worked fine.
  • mark stephens
    mark stephens almost 13 years
    IText is still open source and free but you are expected to pay if you are using it commercially. Seems very reasonable to me!
  • topchef
    topchef almost 13 years
    I specified in the question that both ways are fine: using forms (itext, pdfbox) or xml->pdf (via xsl-fo).
  • home
    home almost 13 years
    Yep, it's still OSS. But looking at the licensing terms it's fairly vague: itextpdf.com/terms-of-use/index.php Extract: Buying such a license is mandatory as soon as you develop commercial activities involving the iText software without disclosing the source code of your own applications. These activities include: offering paid services to customers as an ASP, serving PDFs on the fly in a web application, shipping iText with a closed source product.
  • Jeremias Märki
    Jeremias Märki almost 13 years
    Not really, if I read your requirements. Going with PDFBox or iText, you have to change Java code and recompile if you change the layout. With an XSLT/CSS-based approach (XSL-FO/HTML), you simply change the stylesheet...which, granted, is also some kind of source code, but it's compiled on-the-fly.
  • topchef
    topchef almost 13 years
    @mark stephens - this is not free if the license is subject to such limitations... not sure if it's called open source in that case.
  • topchef
    topchef almost 13 years
    @Jeremias Märki - Going with PDFBox or iText I plan using pdf form to fill it out and generate new pdf (text and/or image fields). Does it make sense? And, of course, both pdf forms and stylesheets are external to Java code so no recompiling.
  • mark stephens
    mark stephens almost 13 years
    So is GPL open source then. That attaches very clear limitations...
  • Mark Storer
    Mark Storer almost 13 years
    Yes, but it's still different from "its commercial software". It's AGPL. AGPL addresses a hole in the GPL with regard to services... people with access to the results need access to the source.
  • Mark Storer
    Mark Storer almost 13 years
    MPL vs AGPL. Not "free" vs "commercial". This is rapidly becoming a Pet Peeve of mine.
  • topchef
    topchef almost 13 years
    thanks for detailed answer! I still have few questions, probably, because of my lack on knowledge of pdf terminology... Do you use terms PDF template and PDF form interchangeably (except for the class PdfTemplate that I understand is not related to either)? Does itext offer support for barcodes so I won't need another library to generate them (leaving how feature rich barcode support is outside this question for now)? thanks, again.
  • topchef
    topchef almost 13 years
    decided on TRYING PDFBox as I already worked with it when using Tika - not final yet...
  • mark stephens
    mark stephens over 12 years
    "friendly" also for commercial use - you do not have to pay to license it in commercial software but you will not get the support and examples you get with IText.
  • Sariq Shaikh
    Sariq Shaikh about 10 years
    @topchef can you please let us know what have you used at the end and how was your experience with it ?
  • topchef
    topchef about 10 years
    @ShaikhMohammedShariq picked PDFBox and had relatively good experience with it but project never went beyond prototype. Main reason for PDFBox was that iText wasn't available for free anymore and FOP was overkill. Clearly, everyone should do their own homework before picking, and quite possible all options evolved since then.
  • Sariq Shaikh
    Sariq Shaikh about 10 years
    @topchef Thanks for the information. This will surely help to narrow down the existing solutions even if we want to consider them for evaluation.
  • Bruno Lowagie
    Bruno Lowagie about 9 years
    It's not very professional to say that iText isn't free software / open source software anymore. For those who don't understand the concept, we've made a 1-minute video that explains it all: youtube.com/watch?v=QHF3xcWnSD4
  • Kalpesh Soni
    Kalpesh Soni about 9 years
    GPL means it cant be used commercially?
  • olejorgenb
    olejorgenb almost 9 years
    @home itext is offered under AGPL. I don't see anything vague about the terms. The extract you posted just tries to clearify that you will have to disclose the source of your own applications if you choose to use the AGPL version..
  • home
    home almost 9 years
    @BrunoLowagie: I'm not the expert with regards to legal aspects so my wording might be wrong. Using the library without disclosing the source is my personal definition of 'free'. Example: I use iText in a huge project for a large company - do I have to disclose my projects' source code?
  • Bruno Lowagie
    Bruno Lowagie almost 9 years
    @home Without knowing the exact context, I would say: yes, the AGPL means that you have to disclose your project's source code. All the code that touches the free iText (AGPL) needs to be free too. Your personal definition about free isn't relevant. The AGPL is what matters.
  • home
    home almost 9 years
    @BrunoLowagie: thanks, but I'd say it's neither my personal definition nor the AGPL - it's all about our customers' requirements. It's not that easy to disclose source code in an enterprise environment. I'm going to update my answer to reflect our discussion...
  • Bruno Lowagie
    Bruno Lowagie almost 9 years
    @home It's not that easy to disclose source code in an enterprise environment and that's why enterprises always have the choice to buy a commercial license that releases them from that requirement. How else do you think iText group could win Deloitte's Fast50 and all those other awards?
  • StartupGuy
    StartupGuy over 7 years
    @home:: "All the code that touches ... iText ... needs to be free too" -- define "touches"!! . It is literally impossible to use iText without the O.S. so by that generalized, vague definition, the OS needs to be AGPL also which is absurd.-- In the case where you simply use an unmodified AGPL library, the terms basically convey, that .. "They do not require you to make available anything else, such as the source code of any software in which you hold the copyright.".
  • frekele
    frekele about 7 years
    100% Apache PDFBox! The Best.
  • Amaneusz
    Amaneusz about 5 years
    I've been working with PdfBox for couple of months now. It's a nightmare.