Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PDF from a Servlet

 
rambabu ravuri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 899
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you set the mime
type to "application/pdf" instead
of "application/x-download"?
 
rambabu ravuri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it, did not make any difference.

Thanks,
Rambabu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic