sreepriyar Posted May 9, 2007 Share Posted May 9, 2007 Hi all, I have a master report with 2 subreports and inside one of the subreport I have another child report. I have to display the PDF format of this report in the IE. Please find code snipped belowCode:InputStream stream1 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/TestFraud.jrxml"«»); JasperDesign jasperDesign = JRXmlLoader.load(stream1); JasperReport subreport1 = JasperCompileManager.compileReport(jasperDesign); InputStream stream2 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/TestFraudPage2.jrxml"«»); jasperDesign = JRXmlLoader.load(stream2); JasperReport subreport2 = JasperCompileManager.compileReport(jasperDesign); InputStream stream3 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/subreport.jrxml"«»); jasperDesign = JRXmlLoader.load(stream3); JasperReport subreport3 = JasperCompileManager.compileReport(jasperDesign); parameters.put("SIMPLE_DATA", SIMPLE_DATA); parameters.put(JRParameter.REPORT_LOCALE, new Locale("en"«»)); ResourceBundle bundle =ResourceBundle.getBundle("MyResources"«»); parameters.put(JRParameter.REPORT_RESOURCE_BUNDLE, bundle); parameters.put("Subreport1", subreport1); parameters.put("Subreport2", subreport2); parameters.put("Subreport3", subreport3); ServletOutputStream sos = response.getOutputStream(); InputStream stream4 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/master.jrxml"«»); jasperDesign = JRXmlLoader.load(stream4); System.out.println("testStream1"«»); byte [] bytes = JasperRunManager.runReportToPdf(stream4, parameters, simpleDS); I get an EOF exception at the point where the PDFis generated. Can some one pls help with the issue? Thanks Link to comment Share on other sites More sharing options...
sreepriyar Posted May 9, 2007 Author Share Posted May 9, 2007 I modified the code in the following manner:Code: InputStream stream1 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/TestFraud.jrxml"«»); JasperReport subreport1 = JasperCompileManager.compileReport(stream1); InputStream stream2 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/TestFraudPage2.jrxml"«»); JasperReport subreport2 = JasperCompileManager.compileReport(stream2); InputStream stream3 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/subreport.jrxml"«»); JasperReport subreport3 = JasperCompileManager.compileReport(stream3); parameters.put("SIMPLE_DATA", SIMPLE_DATA); parameters.put(JRParameter.REPORT_LOCALE, new Locale("en"«»)); ResourceBundle bundle =ResourceBundle.getBundle("MyResources"«»); parameters.put(JRParameter.REPORT_RESOURCE_BUNDLE, bundle); parameters.put("Subreport1", subreport1); parameters.put("Subreport2", subreport2); parameters.put("Subreport3", subreport3); ServletOutputStream sos = response.getOutputStream(); InputStream stream4 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/master.jrxml"«»); JasperReport subreport4 = JasperCompileManager.compileReport(stream4); response.setContentType("application/pdf"«»); // JasperRunManager.runReportToPdfStream(stream4, sos, parameters, simpleDS); byte[] bytes = JasperRunManager.runReportToPdf(subreport4, parameters, simpleDS); sos.write(bytes, 0, bytes.length); sos.flush(); sos.close(); Now I get some junk characters in the browser instead of a PDF File. Can some one please poitn otu the issue? Link to comment Share on other sites More sharing options...
sreepriyar Posted May 9, 2007 Author Share Posted May 9, 2007 I modified the code in the following manner:Code: InputStream stream1 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/TestFraud.jrxml"«»); JasperReport subreport1 = JasperCompileManager.compileReport(stream1); InputStream stream2 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/TestFraudPage2.jrxml"«»); JasperReport subreport2 = JasperCompileManager.compileReport(stream2); InputStream stream3 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/subreport.jrxml"«»); JasperReport subreport3 = JasperCompileManager.compileReport(stream3); parameters.put("SIMPLE_DATA", SIMPLE_DATA); parameters.put(JRParameter.REPORT_LOCALE, new Locale("en"«»)); ResourceBundle bundle =ResourceBundle.getBundle("MyResources"«»); parameters.put(JRParameter.REPORT_RESOURCE_BUNDLE, bundle); parameters.put("Subreport1", subreport1); parameters.put("Subreport2", subreport2); parameters.put("Subreport3", subreport3); ServletOutputStream sos = response.getOutputStream(); InputStream stream4 = getServletConfig().getServletContext().getResourceAsStream("WEB-INF/reports/master.jrxml"«»); JasperReport subreport4 = JasperCompileManager.compileReport(stream4); response.setContentType("application/pdf"«»); // JasperRunManager.runReportToPdfStream(stream4, sos, parameters, simpleDS); byte[] bytes = JasperRunManager.runReportToPdf(subreport4, parameters, simpleDS); sos.write(bytes, 0, bytes.length); sos.flush(); sos.close(); Now I get some junk characters in the browser instead of a PDF File. Can some one please poitn otu the issue? Link to comment Share on other sites More sharing options...
sreepriyar Posted May 9, 2007 Author Share Posted May 9, 2007 Could someone tell me why I get this problem?Caused by: org.xml.sax.SAXParseException: Premature end of file. Any help will be appreciated Link to comment Share on other sites More sharing options...
sreepriyar Posted May 9, 2007 Author Share Posted May 9, 2007 Could someone tell me why I get this problem?Caused by: org.xml.sax.SAXParseException: Premature end of file. Any help will be appreciated Link to comment Share on other sites More sharing options...
chill_work Posted May 9, 2007 Share Posted May 9, 2007 I don't know if this will help you but we don't set our our subreports like you have done. We get the realPath off the request object.Code:String path = request.getSession().getServletContext().getRealPath("/"«»);Of course, this path represents the root level of our webapp. So if your reports are in a subdirectory you will need to modify this. And then we set a specific parameter that JasperReport uses.Code:[code]parameters.put( "SUBREPORT_DIR", path); Then in the subreportExpression we have the following.Code:[code]<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "SomeSubReport.jasper"]]></subreportExpression> This might not solve the EOF or the junk you are getting but it will trim some code down. I would also check your path and make sure that the main report can find your subreports. That was our problem in the past with EOF and why we went with the changes above. Calvin Link to comment Share on other sites More sharing options...
sreepriyar Posted May 9, 2007 Author Share Posted May 9, 2007 The PDf generates locally I mean if I specify a location for the PDF file to be created I can see the PDF file with all details and images. But dispalyign the same in browser, I get junk characters? Code://worksJasperExportManager.exportReportToPdfFile(jasperPrint, "C:/simple_report.pdf"«»);//does not workbyte[] bytes =JasperRunManager.runReportToPdf(subreport4, parameters, simpleDS); response.setContentType("application/pdf"«»); response.setContentLength(bytes.length); sos.write(bytes,0,bytes.length); sos.flush(); sos.close(); 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