59349

How to generate printable (and savable) forms with Java?

Question:

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!

Answer1:

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.

Answer2:

depending on your needs you can either use a reportgenerator like <a href="http://jasperforge.org/projects/jasperreports" rel="nofollow">jasperreports</a> or go for a pdf-library like <a href="http://itextpdf.com/" rel="nofollow">iText</a>

Answer3:

<a href="http://www.docmosis.com" rel="nofollow noreferrer">Docmosis</a> 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.

Answer4:

Thanks for your help! I decided to go with a combination of iText and <a href="http://jexcelapi.sourceforge.net/" rel="nofollow">JXL</a> (an Excel API).

Recommend

  • How to convert triangular matrix indexes in to row, column coordinates?
  • How can I track my input position with multiple inputs using Boost::Spirit::Qi?
  • Dictionary: how to use T as Func's generic type?
  • Java ArrayList Item Counter ie “Apple, 3×Banana, 2×Orange”
  • How to avoid the redefinition of a function (PEP8 error F811)
  • How to get the current URL using wordpress (including index and category pages)
  • How to establish an ssh connection in a Lua script to execute a command on a remote server?
  • Font Awesome in Viewpager Previous Next
  • What is wrong in my MVC implementation?
  • Sum and Average of a series of numbers inputed to a text field
  • Eclipse dark color theme fixes
  • Spring MVC redirect with custom http headers
  • Is it possible to “shrink” a PdfPtable?
  • Open an application in a space using applescripts
  • android-support-v7-appcompat has same attrs as actionbarsherlock library
  • How to use the resource module to measure the running time of a function?
  • How to display the images in listview
  • Unique Permutations - with exceptions
  • SSL client cert authentication for only some URLs?
  • Get the number 18437736874454810627
  • Synchronize windows folders
  • Is there a way to dynamically embed PDF Files in a JSP pulled from the file system?
  • Creating PDF from TIFF image using iText
  • Xstream to map “choice” elements of XML
  • Looking for good analogy/examples for monitor verses semaphore
  • how to upload multiple files in c# windows application
  • How to handle images sent by a mobile device?
  • How to write order and limit within cakephp joins array
  • Xamarin Forms - UWP Fonts
  • What is Eclipse's Declaration View used for?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Can I make an Android app that runs a web view in Chrome 39?
  • Redux, normalised entities and lodash merge
  • Font Awesome Showing Box instead of Icons
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • Calling of Constructors in a Java
  • LevelDB C iterator
  • Linking SubReports Without LinkChild/LinkMaster
  • Is it possible to post an object from jquery to bottle.py?
  • Python/Django TangoWithDjango Models and Databases