Java Reference
In-Depth Information
Exporting to RTF
Rich Text Format (RTF) is a document file format that is supported by most word
processors. Exporting to RTF allows our documents to be read by Microsoft Word
and several other word processors.
Unfortunately, RTF documents generated by JasperReports
are not always readable by OpenOffice.org or StarOffice writer, since
these office suites are not fully compliant with the RTF specification.
In the following example, we will export a report to RTF format.
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.JRRtfExporter;
import net.sf.jasperreports.engine.util.JRLoader;
public class RtfExportDemo
{
public static final String REPORT_DIRECTORY = "reports";
public void rtfExport(String reportName)
{
File file = new File(REPORT_DIRECTORY + "/" + reportName +
".jrprint");
try
{
JasperPrint jasperPrint = (JasperPrint)
JRLoader.loadObject(file);
JRRtfExporter rtfExporter = new JRRtfExporter();
rtfExporter.setParameter(JRExporterParameter.
JASPER_PRINT, jasperPrint);
rtfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
REPORT_DIRECTORY + "/" + reportName + ".rtf");
System.out.println("Exporting report...");
 
Search WWH ::




Custom Search