Problem showing up server generated PDF in Browser

S

sid_mulpuru

This is the code i use to show the PDF in a browser

ByteArrayOutputStream outStream = new ByteArrayOutputStream();
res.setContentType("application/pdf");
res.setHeader("Content-Disposition","inline;Filename= " +
file.getName());

ServletOutputStream sos = res.getOutputStream();
outStream.writeTo(sos);
sos.flush();
outStream.close();
sos.close();

In Netscape i get an error saying the filename does not start with %PDF
and in IE the page just shows up blank. from the blank pagewhen i use
the back button and then hit the forward button the pdf will show up in
IE.

I also tries using fileOuput stream instead of servletoutputstream
FileOutputStream fout = new FileOutputStream( file );

outStream.writeTo(fout);

fout.close() ;

outStream.close() ;

In this case IE does nothing but it works on netscape or mozilla

This is running on websphere 5.0 , apache webserver on linux env

But i need to get this worked on IE any help would be greatly
appreciated!

Thanks in Advance
Sid
 
B

ByteCoder

This is the code i use to show the PDF in a browser

ByteArrayOutputStream outStream = new ByteArrayOutputStream();
res.setContentType("application/pdf");
res.setHeader("Content-Disposition","inline;Filename= " +
file.getName());

ServletOutputStream sos = res.getOutputStream();
outStream.writeTo(sos);
sos.flush();
outStream.close();
sos.close();

In Netscape i get an error saying the filename does not start with
%PDF and in IE the page just shows up blank. from the blank pagewhen
i use the back button and then hit the forward button the pdf will
show up in IE.

To me it seems like you are only sending an empty pdf document (where do
you send the data)?

Maybe you could show me what the outStream.writeTo(sos) method does?
 
S

sid_mulpuru

I just skipped posting over the actual pdf write code.


ByteArrayOutputStream outStream = new ByteArrayOutputStream();

//Write bytes to the PDF
writer = createDocument(document, outStream);
....
...

res.setContentType("applicatio­n/pdf");
res.setHeader("Content-Disposi­tion","inline;Filename= " +
file.getName());


ServletOutputStream sos = res.getOutputStream();
outStream.writeTo(sos);
sos.flush();
outStream.close();
sos.close();

If i use fileOutputStream i can see that the file is being created
physically without any problem. It would not though open up in the
Browser

Thanks
Sid
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top