• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PDF from a Servlet

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it, did not make any difference.

Thanks,
Rambabu
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic