tomsimmons Posted August 8, 2008 Share Posted August 8, 2008 FolksI am trying to output a report as HTML, the eventual goal to actully stream the HTML into an HTML email rather than to screen.I have modified an existing report launcher I use for PDF with the following code...// ServletOutputStream ouputStream = response.getOutputStream();// response.setContentType("application/pdf");// JRPdfExporter pdfExporter = new JRPdfExporter();// pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jPrint);// byte[] output = JasperExportManager.exportReportToPdf(jPrint);// response.setContentLength(output.length);// ouputStream.write(output);// // ouputStream.flush();// ouputStream.close(); PrintWriter pw = response.getWriter(); response.setContentType("text/html"); JRHtmlExporter htmlExporter = new JRHtmlExporter(); htmlExporter.setParameter(JRExporterParameter.JASPER_PRINT, jPrint); htmlExporter.setParameter(JRExporterParameter.OUTPUT_WRITER, pw); htmlExporter.exportReport(); pw.flush(); pw.close();And get the output you see in attachment 1. As can be seen from attachment 2, the commented out PDF works fine, so does the report.There is an image on the page, but it's none of the areas marked with the missing image cross or the other funny blank squares.Is this is caused because I'm not using the image servlet etc or is there another problem? Tom Link to comment Share on other sites More sharing options...
dnvsrikanth Posted August 9, 2008 Share Posted August 9, 2008 HiYou need to use ImageServlet for exporting reports in HTML formatDNV Srikanth Link to comment Share on other sites More sharing options...
tomsimmons Posted August 11, 2008 Author Share Posted August 11, 2008 Thank youI kind of expected that was the going to be the answer.I have now implemented it, but I'm still suffering a couple of problems. The report has a couple of tables that had shaded rectangles to create a background to the headings and the data and lines to seperate the rows of data - see attachment 1 (good table.jpg - this is in PDF format).When the HTML report is generated, this all falls apart - attachment 2 (duff table.jpg). The first tables data isn't displayed at all, neither is the shading, but I do get some lines. The second tables data is present, but no shading or lines.I am currently stuck using JasperReports 1.3.3, I currently don't have full control of the project so I can't upgrade it to 3.Is this a limitation of the HTML export, or a limitation at version 1.3.3? Tom Link to comment Share on other sites More sharing options...
lucianc Posted August 11, 2008 Share Posted August 11, 2008 This is an (inherent) limitation of the HTML exporter (and other grid-exporters such as XLS). See this FAQ.Regards,Lucian Link to comment Share on other sites More sharing options...
tomsimmons Posted August 11, 2008 Author Share Posted August 11, 2008 OKI was just going to report back saying I'd ruled out it being an old version, but that doesn't matter now.If I were to replace the rectangles with themes in the report would they work OK? (assuming that's possible) Tom Link to comment Share on other sites More sharing options...
tomsimmons Posted August 11, 2008 Author Share Posted August 11, 2008 Sorry, I mean Styles not ThemesTom Link to comment Share on other sites More sharing options...
tomsimmons Posted August 11, 2008 Author Share Posted August 11, 2008 To answer my own question....Yes, if you apply styles to the fields then these do render correctly when exported to HTML. Tom Link to comment Share on other sites More sharing options...
tomsimmons Posted August 12, 2008 Author Share Posted August 12, 2008 OKI got this working fine using the PrintWriter to output the HTML in a web page. The problem is that my final goal is export the report as HTML to feed into an HTML email.For this I have changed the JRExporterParameter.OUTPUT_WRITER to JRExporterParameter.OUTPUT_STRING_BUFFER, then fed this into the content of the email.When I receive the email however the result is as though the image servlet stuff isn't being used.Any thoughts? Tom Link to comment Share on other sites More sharing options...
kinslayer2004 Posted November 6, 2008 Share Posted November 6, 2008 HEY tomsimmons , I have the same trouble with images when I´m exporting to HTML Stream to redirect it to the browser, please if you send me an example of you code that resolves the problem, I´ll be glad My Email : aramos@uci.cu thanks in advance AlainCode:public static byte[] exportReportToHtmlStream(JasperPrint jasperPrint, String imagesURI) throws JRException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRHtmlExporter exporter = new JRHtmlExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); exporter.setParameter(JRHtmlExporterParameter.CHARACTER_ENCODING, "ISO-8859-1"); exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, new HashMap()); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image="); exporter.exportReport(); return baos.toByteArray(); }public void generateReport(/*ActionEvent actionEvent,*/ String reportName, Map parameters, Collection data) throws ClassNotFoundException, IOException, JRException { FacesContext context = FacesContext.getCurrentInstance(); try { HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getResponse(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); ServletOutputStream servletOutputStream = response.getOutputStream(); CommonInformation(reportName, parameters, data); response.setContentType("text/html"); response.setHeader("Content-disposition", "inline"); byte[] aux = exportReportToHtmlStream(jasperPrint, imagesURI) ; request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); Enumeration temp = request.getSession().getAttributeNames(); servletOutputStream.write(aux); servletOutputStream.flush(); servletOutputStream.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } context.responseComplete(); }Post Edited by Alain Ramos at 11/07/08 16:48 Link to comment Share on other sites More sharing options...
Teodor Danciu Posted November 13, 2008 Share Posted November 13, 2008 Hi,I will not attempt to explain why the servlet cannot deliver the images to your HTML in the email.What I want to say is that if you really don't have any images or graphics in your report, then it means all those images in the HTML are transparent images used only for aligning. You can suppress the use of transparent images for aligning in HTML if you set this exporter parameter to Boolean.FALSE:http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/export/JRHtmlExporterParameter.html#IS_USING_IMAGES_TO_ALIGNThere is an exporter hint available for the purpose as well:http://jasperreports.sourceforge.net/config.reference.html?group_id=252#net.sf.jasperreports.export.html.using.images.to.align I hope this helps.Teodor 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