Forums Register Login

PDF from a Servlet

+Pie Number of slices to send: Send
I have the following code to print out a pdf to Browser.

When I run, it gives me a pop-up to open or save.
If I "Save" and then open works great.

But if click on "Open" directly Adobe reader opens and gives error message

"There was an Error opening document. This file can not be found!"

Any Suggestions

Thanks,
Ram

---------------------------------------------------------------------
response.setContentType("application/x-download");
String outFileName = "Statement"+FrontEndUtils.getCurrentTime()+".pdf";
response.setHeader("Content-Disposition", "attachment; filename=\""+outFileName+"\"");

//Get Reports - This code prints PDFs to ByteOS
ByteArrayOutputStream byteOS = new ByteArrayOutputStream();
OutputStream out = response.getOutputStream();
reportGenerator.printReport(byteOS);

//Print Reports
response.setContentLength(byteOS.size());
byteOS.writeTo(out);
PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(out));
printWriter.close();
printWriter.flush();
-----------------------------------------------------------------------

[ November 07, 2005: Message edited by: rambabu ravuri ]
[ November 07, 2005: Message edited by: rambabu ravuri ]
+Pie Number of slices to send: Send
What happens if you set the mime
type to "application/pdf" instead
of "application/x-download"?
+Pie Number of slices to send: Send
I tried it, did not make any difference.

Thanks,
Rambabu
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1054 times.
Similar Threads
PDF Stream HTTP Vs HTTPS
Strange problem while creating zip file
New to servlets
PdfBox, do you have to save the .pdf to a file?
print writer
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 08:08:24.