Exporting to HTML

Exporting to HTML is another common requirement. The following example demonstrates how to do it:

package net.ensode.jasperbook;

import java.io.File;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRHtmlExporter;
import net.sf.jasperreports.engine.util.JRLoader;

public class HtmlExportDemo
{
  public static final String REPORT_DIRECTORY = "reports";

  public void htmlExport(String reportName)
  {
    File file = new File(REPORT_DIRECTORY + "/" + reportName +".jrprint");
    try
    {
      JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(file);
 JRHtmlExporter htmlExporter = new JRHtmlExporter(); ...

Get JasperReports 3.5 for Java Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.