> I get Base64 encoded String for a PDF file. I convert that String to
> character array. Then I decode it back to byte array. Now, I need to
[quoted text clipped - 37 lines]
> Any help with code will be appreciated.
> sgho@aol.com
This is the problem:
PDF never gets displayed in browser (neither in IE, not Netscape etc.).
My input argument is byte array. I want to display PDF in IE browser
from that byte array from within doGet method of servlet.
I get correct number of buyes back from PDF.
Code is:
// Setting all headers (as shown below)
byte[] inBytes = getBytesFromPDF(...);
//I succesfully get bytes from PDF.
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
if(inBytes !=null){
outStream.write(inBytes);
}
outStream.flush();
I have set following headers before executing the above code:
resp.setContentType("application/pdf");
resp.setHeader("Expires", "0");
resp.setHeader("Cache-Control","must-revalidate, post-check=0,
pre-check=0");
resp.setHeader("Pragma", "public");
resp.setHeader("Pragma", "no-cache"); //HTTP 1.0
resp.setDateHeader("Expires", 0); //prevents caching at the proxy
server
resp.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
resp.setHeader("Cache-Control", "max-age=0");
resp.setHeader("Content-disposition", "inline; filename=stuff.pdf");
Someone suggested to add dummy PDF filename for displaying. I added
stuff.pdf as dummy PDF name with no luck.
Alex - 21 Oct 2005 17:43 GMT
First of all, ditch all "setHeader" calls. Then after setContentType call,
add this:
resp.setContentLength(inBytes.length);
You may still have a problem with IE, if you back out of the page displaying
your PDF doc, and then move into it again, using BACK and FORWARD buttons.
You will be better off saving your PDF doc in a temporary file, and
redirecting the response, like this:
String fileName = ...
<make the file>
resp.sendRedirect(fileName);
AM
> This is the problem:
> PDF never gets displayed in browser (neither in IE, not Netscape etc.).
[quoted text clipped - 35 lines]
> Someone suggested to add dummy PDF filename for displaying. I added
> stuff.pdf as dummy PDF name with no luck.
Roedy Green - 22 Oct 2005 01:02 GMT
>This is the problem:
>PDF never gets displayed in browser (neither in IE, not Netscape etc.).
>
>My input argument is byte array. I want to display PDF in IE browser
>from that byte array from within doGet method of servlet.
In a thin client situation, the browser sends a request, then the
sever sends back the pdf file with a header.
The request contains a list of the sort of responses it is prepared to
hear.
In your case, where does the request come from? the browser sending
in an URL or an Applet? If an Applet, the browser knows nothing about
the request. The Applet has to deal with the response.
If in your case there is no Applet involved, I would tackle it this
way.
Get a packet sniffer. http://mindprod.com/jgloss/sniffer.html
Watch your browser download a PDF file not using your code, and watch
it using your code. Compare the packets and that may give you a clue.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Ingo R. Homann - 24 Oct 2005 10:09 GMT
Hi SG,
> byte[] inBytes = getBytesFromPDF(...);
> ...
(1) Are you sure, your getBytesFromPDF() returns a valid PDF-File?
(2) Especially when using the IE (in some versions), the Request is
often executed twice: First, the IE requests the content. It realizes
from the header, that the content is PDF and should be displayed with
the AcroReader. It opens AcroReader and passes the URL (not its
content!) to it. So, AcroReader requests the URL from the server again!
Without knowing how your getBytesFromPDF works, maybe, this is a problem?
Ciao,
Ingo