WebSphere Portal Server - Damaged PDF exported when using Jasper Report in WPS 5

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Portal Server > April 2007 > Damaged PDF exported when using Jasper Report in WPS 5





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Damaged PDF exported when using Jasper Report in WPS 5

2007-04-13, 1:26 am

I have developed a printing function in Struts Portlet that once 'Print' button is clicked by the user, an PDF file will be exported with Jasper Report, and the user can save or open it to print out.
Here is my code snippet:
/***********************/
HttpServletResponse httpServletResponse = (HttpServletResponse) portletResponse;
httpServletResponse.setContentType("application/pdf");
ServletOutputStream outputStream = httpServletResponse.getOutputStream();

InputStream inputStream = this.getServlet().getServletConfig().getServletContext().getResourceAsStream("/rpt/Flights.jasper");

JRBeanCollectionDataSource beanDataSource = new JRBeanCollectionDataSource(filghts); //'flights' is a pre-defined arraylist contains all records to be printed

//Export PDF file
JasperRunManager.runReportToPdfStream(inputStream, outputStream, new HashMap(), beanDataSource);
outputStream.flush();
outputStream.close();
/***********************/
A PDF file can be exported when run that code, but when I try to open it, there is an error message 'The file is damaged'.
Therefore, I tried another method -Export the report to a FileOutputStream,
Replace the outputStream in the code with:

FileOutputStream outputStream = new FileOutputStream(new File("C:\\report.pdf"));

It works very well. I opened the PDFs exported with two different method with UltraEdit, and found out the difference: when using ServletOutputStream, HTML code of portlet was appended after 'EOF' of the PDF!

How can I privent that useless HTML to be appended? Can I configure the ServletOutputStream of portletresponse? All suggestions are appreciated.




Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com