Jump to content

JasperReport exported as HTML


tomsimmons

Recommended Posts

Folks

I 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

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Thank you

I 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

OK

I 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

  • 2 months later...

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

 

Alain

Code:
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

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_ALIGN

There 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...