Java Reference
In-Depth Information
try
{
JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(file);
JRTextExporter textExporter = new JRTextExporter();
textExporter.setParameter(JRExporterParameter.JASPER_PRINT,
jasperPrint);
textExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
REPORT_DIRECTORY + "/" + reportName + ".txt");
textExporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH,
new Integer(10));
textExporter.setParameter(JRTextExporterParameter.
CHARACTER_HEIGHT, new Integer(10));
System.out.println("Exporting report...");
textExporter.exportReport();
System.out.println("Done!");
}
catch (JRException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new PlainTextExportDemo().plainTextExport(args[0]);
}
}
After compiling and executing the above code with the report generated by the
JRXML template we have just written, we should have a text file with the following
contents in our hard drive:
Text Heavy Report
Exporting to plain text makes more sense when the
report is completely (or mostly) text.
Since tables and graphical elements don't translate to
plain text very well.
We created this report template to demonstrate
exporting to plain text.
Exciting, isn't it?
Notice, in this example, we had to set some parameters in addition to the
output file name. The JRTextExporterParameter.CHARACTER_WIDTH and
JRTextExporterParameter.CHARACTER_HEIGHT parameters tell JasperReports how
 
Search WWH ::




Custom Search