Some day ago my boss asked me that he wanted invoices in PDFs from out web application. Given that everybody uses JasperReports and iReport for design I tried it. My web app is based on Java+Hibernate and Spring. At the beginning Jasper seemed fine and iReport too. Anyway I've been stopped by two things:
I've seen DynamicJasper, but, it seems that I can't design reports with it. What do you think? Are there easier to use alternatives?
jrxml is a human readable XML file that contains the report template i.e. report structure and its formatting rules. . jasper is the compiled report template i.e. compiled .
JasperReports is an open source Java reporting tool that can write to a variety of targets, such as: screen, a printer, into PDF, HTML, Microsoft Excel, RTF, ODT, comma-separated values (CSV) or XML files.
At JasperReports levelIn <jasperserver-root>/WEB-IN/classes you can find the file jasperreports. properties. This is the file that you need to modify to set some properties to the value you want for all reports running in JasperReports Server. Similarly you can set some properties at iReport level.
If time is of the essence (as is usually the case when your boss hands you something) I would recommend checking out iText (main site is here).
It is very, very simple to learn (you can have it up, running, and generating simple "Hello, PDF!" examples in 20 minutes) and can export just about anything into PDF: tables, lists, charts, images, hypertext, etc.
By my own admission, JasperReports implementing its JRBeanCollectionDataSource
is a more elegant, flexible, permanent solution for you. But if you need a quick-n-dirty library to just produce PDFs, and looming deadlines are drawing nigh, I would download the iText JAR and have at it.
The site is loaded with practical code examples for just about anything you would want to accomplish.
Unlike JasperReports, iText is not a report generator. Its just a PDF generator (which, from what I can tell in your question, sounds like all you need). So, for any particular Bean, you would just select the properties you want exported to the PDF invoice, and use the Chunk
, Paragraph
, etc. classes to append them to the document as you need:
// Your POJO/Bean/VO
Employee oEmp = new Employee();
Document oInvoicePdf = new Document();
PdfWriter.getInstance(document, new FileOutputStream("/invoices/2011/Invoice201.pdf"));
document.open();
document.add(new Chunk("Employee's name is : " + oEmp.getName()));
document.close();
Even if this is not what you're looking for, at all costs I would recommend you steer clear of Apache PdfBox. In my humble opinion, it is pure evil and will only break your heart.
Hope this helps, and best of luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With