aspose 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
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: 863
    
    1
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
 
 
subject: PDF from a Servlet