I'm working on an invoice program for a local accounting company. What is a good way to create a PDF file with Java? Any good library? I'm totally new to PDF export (On any language).
2,741 6 6 gold badges 40 40 silver badges 64 64 bronze badges asked Sep 8, 2011 at 21:56 1,754 6 6 gold badges 22 22 silver badges 41 41 bronze badges Commented Sep 23, 2011 at 15:58I prefer outputting my data into XML (using Castor, XStream or JAXB), then transforming it using a XSLT stylesheet into XSL-FO and render that with Apache FOP into PDF. Worked so far for 10-page reports and 400-page manuals. I found this more flexible and stylable than generating PDFs in code using iText.
3 3 3 bronze badges answered Sep 8, 2011 at 22:04 Philipp Reichart Philipp Reichart 20.9k 6 6 gold badges 59 59 silver badges 65 65 bronze badgesHow fast can this convert a 400 page manual into PDF? I've used iText, but it's too slow for some of our large documents.
Commented Mar 4, 2013 at 16:37Sorry, I did this back in 2005-2007, but IIRC it was sub-second for a simple 10-page report (with a cached stylesheet) and dozens of seconds for a more complex 400 page report. Do cache the parsed XSL stylesheet when you need to generate same/similar reports with different data -- makes for quite a boost.
Commented Mar 4, 2013 at 18:20 I can also recommend Velocity for outputting data to xml. Commented Nov 24, 2014 at 18:37You could also use freemarker to output xml/html and pump the string into iText. It's a lot like how you do it, but freemarker is a very good template engine.
Commented Jun 3, 2015 at 14:40Following are few libraries to create PDF with Java:
I have used iText for genarating PDF's with a little bit of pain in the past.
Or you can try using FOP: FOP is an XSL formatter written in Java. It is used in conjunction with an XSLT transformation engine to format XML documents into PDF.
12k 9 9 gold badges 67 67 silver badges 89 89 bronze badges answered Sep 8, 2011 at 22:08 Ritesh Mengji Ritesh Mengji 6,120 9 9 gold badges 31 31 silver badges 46 46 bronze badgesOn iText site I read that their AGPL licence requires from you "distribution of all source code including your own product, including if it is a web-based application", among other things. Seems to be completely unacceptable for any commercial project.
Commented Jan 24, 2013 at 13:13 @mvmn: You can buy a commercial license. Commented Mar 25, 2014 at 5:43 Or you can use iText 1.3 which is GNU Affero General Public License v3 Commented May 21, 2014 at 14:25 @mvmn Your link is broken :( Commented Apr 20, 2020 at 18:07Another alternative would be JasperReports: JasperReports Library. It uses iText itself and is more than a PDF library you asked for, but if it fits your needs I'd go for it.
Simply put, it allows you to design reports that can be filled during runtime. If you use a custom datasource, you might be able to integrate JasperReports easily into the existing system. It would save you the whole layouting troubles, e.g. when invoices span over more sites where each side should have a footer and so on.