How to output/dump JSP data into a pdf file?

Christopher Koenigsberg

We send pdf content to browsers all the time. We do it from a servlet, rather than from a jsp.

There were problems (you have to experiment and try various things in various browsers etc. till you get it right), in getting the browser plugins to always display the pdf content correctly. I think you have to get the content-length response header exactly right, for instance, or else some versions of IE, with some versions of the Acrobat Reader plugin, will just show an empty window. Also you may have to try different buffer sizes in the servlet, to make sure that, for instance, pdf's with less than 5 pages don't come out blank, in some IE/plugin versions (I think the protocol IE talks with its plugin is flaky, and subject to problems with buffering etc.).

And maybe because of these reasons, or related ones, I forget (you'll need to experiment), sometimes the IE browsers, for some older versions (4.0), would not always recognize the content type correctly, in some instances. They would always prompt you to download and save the unknown content, instead of firing up the pdf content.

But we found that the external Acrobat Reader helper app is more reliable than the plugin with IE; the external version usually displays the pdf content OK, e.g. with Netscape or Mozilla or Opera etc., even when the plugin for IE won't recognize (makes you download & save) or won't display (shows empty page) the same exact content.