dnvsrikanth Posted June 23, 2009 Share Posted June 23, 2009 Hi, I am using JasperReports to generate reports in my project. I will generate the report using an OutputStream and display it in a JSF page. I use JR version 2.0.5 and Apache Trinidad 1.0.5 in my application. The problem here is exporting to excel and pdf formats are not working properly. When I export to an excel file i see all junk data in the file/stream. And when I export it to pdf the report is blank without any data. Its working fine when I export the report to html, rtf and xml formats Please help me out in this regard. Thanks ,DNV Srikanth.Post Edited by dnvsrikanth at 06/23/2009 10:03Post Edited by dnvsrikanth at 06/23/2009 10:17 Link to comment Share on other sites More sharing options...
blaguman Posted June 24, 2009 Share Posted June 24, 2009 Hi. For your pdf export, are you passing a datasource to your report ? Regards,Morgan Link to comment Share on other sites More sharing options...
dnvsrikanth Posted June 24, 2009 Author Share Posted June 24, 2009 Hi, Yes I am passing datasource to my report Thanks,DNV Srikanth. Link to comment Share on other sites More sharing options...
blaguman Posted June 24, 2009 Share Posted June 24, 2009 In the pdf export, the usual reason of a blank page is the integrity of the datasource passed to the report. Check if you're actually passing a good datasource (object integrity and content), and check the "When no data type" section in your report.You can also try, just to see the result, with a JREmptyDataSource object instead of your datasource. Then we'll see what we can do :)For the xls file, I'm sorry but I cannot help you, I've never tried to export in xls. Regards,Morgan Link to comment Share on other sites More sharing options...
dnvsrikanth Posted June 24, 2009 Author Share Posted June 24, 2009 Hi I am getting a ResultSet by calling a stored procedure by using a callable statement and thereby passing a JRResultSetDataSource to the report. Even I have set whenNoDataType to AllSectionsNoDetail also in my report. Thanks,DNV Srikanth Link to comment Share on other sites More sharing options...
dnvsrikanth Posted June 29, 2009 Author Share Posted June 29, 2009 hi, Any help in this regard?? Thanks,DNV Srikanth. Link to comment Share on other sites More sharing options...
teodord Posted July 7, 2009 Share Posted July 7, 2009 Hi, Not sure what you mean by "i see all junk data in the file/stream". You mean the propert Excel viewer is not opening and you end up with a text viewer displaying binary content?What about PDF. Do you see the PDF viewer opening? Or nothing opens and you end up with a blank browser page? Thanks,Teodor Link to comment Share on other sites More sharing options...
dnvsrikanth Posted July 7, 2009 Author Share Posted July 7, 2009 Hi Teodard, When I run the report in a web application these problems occur. I am trying to display the report in a JSF page So when I try to export the page to pdf stream it is displaying blank pdf stream and the excel stream displays all junk data. DNV Srikanth. Link to comment Share on other sites More sharing options...
teodord Posted July 7, 2009 Share Posted July 7, 2009 Hi, I'm afraid you did not answer my questions, or I'm not able to undestand what you are saying.In this case, it would be better to post some screen shots so we can see what the problem is. Thank you,Teodor Link to comment Share on other sites More sharing options...
dnvsrikanth Posted July 8, 2009 Author Share Posted July 8, 2009 Hi, I am herewith attching the screenshts of the report exported to HTML, PDF and EXCEL formats. Thanks,DNV Srikanth. Link to comment Share on other sites More sharing options...
teodord Posted July 8, 2009 Share Posted July 8, 2009 Hi, OK. Now it would be interesting to see how you are working with those output streams to deliver the binary content to the browser.Let's start with PDF. Can you post some code snippets here? Thanks,Teodor Link to comment Share on other sites More sharing options...
dnvsrikanth Posted July 8, 2009 Author Share Posted July 8, 2009 Hi, This is the code I am using to export the report to pdfstream:From the JSF page am passing a parameter to Java Generator Class and exporting the report based on the parameter passed. DNV SrikanthCode:if(formatType.equals("pdf")){JRExporter exporter = null;exporter = new JRPdfExporter();response.setContentType("application/pdf");response.setHeader("Content-Disposition","inline;filename=\""+reportName+".pdf\"");exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());exporter.exportReport();} Link to comment Share on other sites More sharing options...
teodord Posted July 8, 2009 Share Posted July 8, 2009 Hi, I'm afraid this is a bit too simplistic. Delivering PDF to the browser is a little more tricky.Some browsers (including IE in your screenshot) have to know before hand how many bytes are going to be delivered, before even starting to send those bytes through the response output stream.This means that you would have to measure the length of the PDF file before sending it to the browser.Streams have to be closed properly and stuff like that.So I encourage you to take a look at the PdfServelet class that we ship as part of the JR library. You might even want to use it. Check the /demo/samples/webapp sample inside the JR project to see how.The source of this servlet is here and you can see what we are doing in order to ensure PDF will come out nicely on all browsers:http://jasperforge.org/scm/viewvc.php/trunk/jasperreports/src/net/sf/jasperreports/j2ee/servlets/PdfServlet.java?root=jasperreports&view=markup I hope this helps.Teodor Link to comment Share on other sites More sharing options...
dnvsrikanth Posted July 8, 2009 Author Share Posted July 8, 2009 Hi Thank you, I'll check the link provided and implement as you have mentioned. But the code I have mentioned worked properly. But later logging was implemented in the application and everything was fine except these exports. Anyhow I'll refer the link mentioned. And this is the code am using for excel stream: Thanks,DNV SrikanthCode:if(formatType.equals("excel")) { ServletOutputStream outputStream= response.getOutputStream(); exporter = new JExcelApiExporter(); ByteArrayOutputStream xlsReport = new ByteArrayOutputStream(); response.setContentType("application/xls"); response.setHeader("Content-Disposition", "inline; filename=\""+reportName+".xls\""); exporter.setParameter(JExcelApiExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JExcelApiExporterParameter.OUTPUT_STREAM, xlsReport); exporter.setParameter(JExcelApiExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.FALSE); exporter.setParameter(JExcelApiExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE); exporter.setParameter(JExcelApiExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE); exporter.setParameter(JExcelApiExporterParameter.IS_FONT_SIZE_FIX_ENABLED, Boolean.TRUE); exporter.setParameter(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); exporter.exportReport(); byte bytes[] = xlsReport.toByteArray(); response.setContentLength(bytes.length); outputStream.write(bytes, 0, bytes.length); outputStream.flush(); outputStream.close(); } Link to comment Share on other sites More sharing options...
teodord Posted July 8, 2009 Share Posted July 8, 2009 Hi,Try solve the PDF problem first. See if connecting with Firefox works.Note that in JasperRepors we also have servlets for delivering XLS content. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
dnvsrikanth Posted November 6, 2009 Author Share Posted November 6, 2009 Hi I have found the problem. As I have said earlier some code change to implement logging creted this mess and I reverted that change by reverting that change> I haven't made changes to the exporting code snippet whatever I have posted earlier in this thread. Thanks,DNV Srikanth. Link to comment Share on other sites More sharing options...
sandeeppandey15 Posted November 9, 2009 Share Posted November 9, 2009 Hi ,I am trying to export some data on excel sheet using ireport , some columns are having huge data so generated excel sheet cells size are not uniform.How to make it uniform using ireport(Suppose height 15) without turnicating data??Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now