This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Murach's MySQL and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

Images in PDF files problem for ServletOutputStream

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I've searched a lot but could not solve this problem. I am generating PDF files with iText. If i use FileOutputStream everything is fine but when i try to use ServletOutputStream the images does not appear in PDF files.

When I open the PDF file with text editor, i saw that there "???" so much. That means something is shaving the bytes. It is like trying to use binary files with JSP. But i am using JSF, Tomcat 6.0, Spring 3.0 and Richfaces.

Here is the code that generates PDF with ServletOutputStream and causes problem


And here is the code works fine with FileOutputStream()


I could not find why the bytes are being shaved.

Thanks a lot for your help,
 
Sercio Narsever
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the solution that worked fine. Thanks to BalusC on stackoverflow.


When taking the response fully in your hands in JSF, you need to ensure that you call

response.reset();
before you set the headers, there is namely little chance that there's already something been set/written on the response (more than often by some sort of custom Filter).

You also need to ensure that you call

out.close();
instead of out.flush() to prevent that any other bytes will be written to the response body afterwards.

Finally, in JSF you need to call

FacesContext.getCurrentInstance().responseComplete();
to prevent that JSF will forward the request/response to a view (render the response).
reply
    Bookmark Topic Watch Topic
  • New Topic