File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes PDF from a Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "PDF from a Servlet" Watch "PDF from a Servlet" New topic
Author

PDF from a Servlet

rambabu ravuri
Greenhorn

Joined: Apr 18, 2005
Posts: 11
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 ]
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
What happens if you set the mime
type to "application/pdf" instead
of "application/x-download"?


bitguru blog
rambabu ravuri
Greenhorn

Joined: Apr 18, 2005
Posts: 11
I tried it, did not make any difference.

Thanks,
Rambabu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PDF from a Servlet
 
Similar Threads
print writer
PDF Stream HTTP Vs HTTPS
Strange problem while creating zip file
PdfBox, do you have to save the .pdf to a file?
New to servlets