What is the easiest way to convert the output of a JSP to PDF?

Dan Waldner

There are a number of ways of converting JSP output to a PDF file. One such way is listed here as HTML to PS then PS to PDF. This way often gets corrupted or doesn't look the way you want it to look. If this happens, there are two ways of doing what you want:

(Intermediate difficulty): Use an FDF form to populate a PDF template. FDF is the form data file that adobe uses to populate its PDF files that have Form Fields within the text. This is versitile and can do 90% of what most people will require on a text readout for a report.

(Advanced difficulty): Output all your data from your report JSP into an XML output, combine that output with an XSL-FO stylesheet and generate an FO file which can be read by FOP, a product by the Apache group (xml.apache.org). This is the most versitile option, and can do ANYTHING you want to do w.r.t. PDF files. Where I work, we are using this to generate reports for users similar to what you want to do. Look into this, as this is, likely, the best option.

Check the xml.apache.org/fop website for examples. Its riddled with them (albeit not too many instructions, but the files themselves are pretty straight forward to understand). If you are familiar with XML and XSL, XSL-FO is just another type of XSL file that contains FO tags rather than HTML tags. When combined with your XML document that contains all the information you want to place on the PDF file, using a program like XT from www.jclark.com, you will receive a .FO file. Now that you have this FO file, you can feed it directly to FOP to translate into PDF. Its kinda tricky, but this is the logic flow XML + XSL-FO --> FO --> PDF using XT --> FOP. If you would like, drop me an email at d_waldner@hotmail.com and I'll email you out some examples of working XML and XSL-FO for you to figure out.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact