You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Zhou, Wufeng" <wz...@nsf.gov> on 2001/04/05 15:51:20 UTC
RE: Work-around for IE 5.5 Bug to display PDF
Besides the points made by Steve below, I know for a fact that Microsoft
acknowledged
it's a bug in IE 5.5 that trying to POST PDF will cause a blank doc.
So if the following still does not work, you may want to use redirect or
dispatch
to a new servlet that send the document back in doGet() method.
Hope this helps.
Wufeng
> -----Original Message-----
> From: Stephen Thompson [SMTP:shag_vt@yahoo.com]
> Sent: Thursday, April 05, 2001 8:31 AM
> To: fop-dev@xml.apache.org
> Subject: Work-around for IE 5.5 Bug
>
> Hi folks - saw Marina's post yesterday about returning PDFs from a servlet
> causing IE to show a blank doc.
>
> >In a nutshell:
> >I have a servlet that generates a pdf file and sends it to
> >a client in a stream. This works fine in all the browsers
> >except IE5.5, which do runs the Acrobat Reader trailer but
> >does not display anything.
>
> There is a very reliable work-around to this - tell the browser how big
> the PDF is before you write it to the stream. Here is my code:
>
> protected void serveDocument( HttpServletRequest request,
> HttpServletResponse reply, String xml )
> throws java.io.IOException, javax.servlet.ServletException
> {
> java.io.ByteArrayOutputStream transform = new
> java.io.ByteArrayOutputStream();
>
> new corning.cds.command.PDFTransform().transformToPDF(
> corning.cds.command.PDFTransform.TYPE_CABLE_DATA,
> xml,
> transform
> );
>
> byte[] pdfDoc = transform.toByteArray();
>
> reply.setContentType( "application/pdf" );
> reply.setContentLength( pdfDoc.length ); // !!! KEY LINE !!!
> reply.getOutputStream().write( pdfDoc);
> reply.getOutputStream().flush();
> reply.getOutputStream().close();
> }
>
>
> Closing the stream at the end was a sometimes fix, but when I added the
> setContentLength line, that gave me 100% reliable. Of course, the trick
> is that you have to know exactly how many bytes you are writing *before
> you write them*. Once the first packet has been sent back to the client,
> it is too late to add header information.
>
> So what you do is write the PDF to a ByteArrayOutputStream. Then you can
> access the byte array before you send it, meaning you can see exactly how
> long it is. Bingo!
>
> Hope this helps.
> Steve
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> For additional commands, email: fop-dev-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org