Hi again, 
I seem to have solved part of the issue (still have some cases when it
is occuring though).
Thought this might be a useful to someone else:
IE will sometime make more than one GET request to retrieve a PDF,
this is referenced here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;293792
One of the request will be to get the content type only, and is
hardcoded to time out after 10 seconds (which is not a lot if you're
building a big pdf)

Basically the trick is to watch for the 'contype' user agent, and
return only headers, for instance in a servlet:
--
if (request.getHeader("user-agent").equals("contype")){
response.setContentType("application/x-pdf");
response.setStatus(200);
}
else {
// actually return PDF
}
--

Another addition would be (for instance in the progress servlet) to
add the content-type and no-cach headers to the html page sent (this
takes care of most caching issues, where IE still thinks the PDF is an
html page), e.g:
--
if (!currentPdf.isdone){
response.setContentType("text/html");
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0,
pre-check=0");
response.setHeader("Pragma", "No-Cache");
response.setHeader("Refresh","5"); 
// write to servletoutputstream
}
else { //send actual pdf here}
--

Nonetheless, I still have the 'File does not begin with %Pdf' issue
under load in some cases where IE makes more that one request for the
PDF (viewable in the http traffic), but closes one unexpectedly: I
still have no clue as to why it's doing that, or how to cope with it 
since the headers sent are exactly the same.... :-(

Hope this helps,

PS: thanks for itext it is really a wonderful library to work with !

On Thu, 17 Feb 2005 10:12:06 +0100, Ziad WAKIM <[EMAIL PROTECTED]> wrote:
> Hi All,
> I'm having a strange case of 'File does not begin with %pdf' issue
> with a servlet I'm using.
> The servlet basically merges PDF (roughly based on the sample itext
> code), and then feed it back to the browser:
> 
> Flow goes like this: When the servlet is called it spawns a thread
> (called pj here), that handles merging, and returns a
> ByteArrayOutputStream which is then fed to the browser like this :
> --
> response.setBufferSize(2048);
> response.setContentType("application/x-pdf");
> response.setHeader("Expires", "0");
> response.setHeader("Cache-Control", "must-revalidate, post-check=0,
> pre-check=0");
> response.setHeader("Pragma", "public");
> response.setContentLength(pj.getBaosSize());
> response.setHeader("Content-disposition", " inline; filename=Test.pdf");
> ServletOutputStream sos;
>                       try {
>                           sos = response.getOutputStream();
>                          pj.getBaos().writeTo(sos);
>                           sos.flush();
>                       } catch (IOException e) {
>                           e.printStackTrace();
>                       }
> --
> now most of the time this works, but occasionnaly, on browser using
> acrobat 5 or 6, it shows a 'File does not begin with %pdf' message' .
> Usually, reloading the page seems to display it correctly, but
> sometimes it just won't work, typically under load.
> 
> Note that I'm aware that adobe recommends somewhere not using the
> plugin and using the reader instead, but I need PDFs to be displayed
> in a frame as part of my application, so it is not an option for me.
> 
> Any idea or help would be appreciated.
> 
> --
> m o t d i e m
> 


-- 
z i a d


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to