tags:

views:

44

answers:

4

Here is my situation. I have written a Database application in Java. Now (unfortunately as an afterthought) I want to generate forms from data I pull from the database.

By form I mean a savable and printable file (not anything to do with UIs or swing). Basically I want to take a template form and fill in things from the data I pull from the database.

Is there any simple API for this? I really don't care about the file format, it just has to be savable and printable (pdf, word, open office, ect.). Forms have to be able to have differing fonts and possibly images though.

I looked at Apache POI for MS Word docs, and a few other APIs and these seem extremely painful.

Has anyone had a good experience with any particular API?

Thanks for your help!

+4  A: 

depending on your needs you can either use a reportgenerator like jasperreports or go for a pdf-library like iText

Nikolaus Gradwohl
Having used iText before for exactly the same purpose, I can vouch for this. +1.
Vineet Reynolds
A: 

Docmosis is a good library as well for populating templates and outputting various formats. I have seen some places using both iText and Docmosis because each has strengths.

jowierun
+1  A: 

I would recommend iText because it gives you the functionality of writing Graphics2D to the PDF canvas, which means you can easily embed images and such in your form.

A minor issue with the library is that the best examples, I believe, are in the "iText in action" book by Bruno Lowagie (ISBN: 1932394796), which costs around 50 dollars US.

iText can have a rather steep learning curve, but for forms and such it should be fairly easy. Another advantage is that it can be used in combination with e.g. JFreeChart.

If you only want to fill out already generated PDF forms, iText is the way to go, since it has some great abstractions for doing exactly that.

Jes
DRJTower
It is fairly easy to fill templates. Editing a pdf IS problematic, but since a form uses the AcroForm standard, you don't actually edit the pdf element, you just put data in it.It is quite simple to fill the form, it's a matter of putting some strings in a data structure and mapping them to the variable names of the given template.
Jes
A: 

Thanks for your help! I decided to go with a combination of iText and JXL (an Excel API).

DRJTower