I just completed an application that mixes PDF forms with JSPs. iText was wonderful, but I must say that dealing with the interactions between various versions of various web browsers and versions of Acrobat Reader was quite a challenge.
I did finally get things to work consistently, and here are some of the lessons that I learned: 1. MSIE generally ignores the content-type header. It is a good idea to set it for those browsers that are actually standards-compliant, but MSIE is not. The only way to make sure that MSIE will open a PDF correctly is to ensure that MSIE requests a file with the ".pdf" extension. While the following solution may be overkill, it works consistently: Instead of having the browser request a servlet or a JSP, and having that servlet or JSP directly write the PDF to the browser, I have the servlet or JSP produce HTML with an <embed> tag that references a .pdf file. In the web server / servlet container config (I'm using Tomcat), I configure a servlet mapping for "*.pdf" to be sent to my PDF-producing servlet. The reference in the <embed> tag has parameters telling the servlet how to get the data for the PDF. The <embed> tag causes the browser to request a PDF. The servlet returns a PDF, and MSIE happily loads the Acrobat Reader plug-in and displays the PDF. Besides resolving the MIME-type issue, this also gets around nasty problems like the PDF being handled by the full version of Acrobat (not the reader), if it is installed, and issues about opening Reader in the proper window, etc. 2. It is virtually impossible to completely turn off caching in Acrobat Reader. To deal with this, I make sure that PDF reference in the <embed> tag has a unique name. I append the current timestamp, to the millisecond, to the root pdf file name. Reader sees this as a "new" document, and doesn't show cached data in the form fields. ======================================= Rich Freedman Senior Software Engineer Cross Current Corporation 100 Union Square Drive New Hope, PA 18938 Email: mailto:[EMAIL PROTECTED] Web: http://www.CrossCurrent.com ======================================= -----Original Message----- >Date: Tue, 1 Jul 2003 15:47:27 +0200 >From: Bruno <[EMAIL PROTECTED]> >To: [EMAIL PROTECTED] >Subject: RE: [iText-questions] Update on Creating PDF via Servlet > >Quoting Brook Stevens <[EMAIL PROTECTED]>: > >> I don't know anything about any other servlets, >> but I use the following code >> in servlet environment. I may, however, not understand your >> question/setup enough for this to be useful. > >Don't worry, I wrote iText especially to use in a Servlet >environment and I don't understand the problem either... > >The only two possible problems I can think of are described >in the iText FAQ (but I suppose the FAQ is the first thing >somebody reads): >1. the JSP screws up the PDF because there are newlines in it. >2. it's a browser-problem, not a Servlet problem. > >Bruno ------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 _______________________________________________ iText-questions mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/itext-questions
