JasperReports Ultimate Guide - Sample Reference - Schema Reference - Configuration Reference - API (Javadoc)
|
|
|
|
JasperReports - Text Export Sample (version 4.6.0) | |
|
|
|
Main Features in This Sample | |
| Exporting to Pure Text Format |
|
|
||||
top | |||||
|
|||||
Exporting to Pure Text Format | Documented by Sanda Zaharia | ||||
|
|||||
| Description / Goal |
| How to export reports to plain text files. | ||
| Since |
| 1.0.1 | ||
|
|||||
|
Plain Text Export - Overview
One could imagine situations which require the text information from a JasperReport document to be saved separately as pure text document. In this case graphics, images, styles and pixel perfectness are not conserved. Text elements are converted into simple texts to be written in documents with predefined page widths and heights, measured in characters. The JRTextExporter implementation is intended to serve to this purpose. Users can specify the desired page width and height (in characters), then the engine will try to best fit text elements into the corresponding text page. Taking into account that positions and sizes are measured in pixels in a JasperReports template, and page dimensions in a text document are set in number of characters, some precautions must be taken when creating reports for text export:
The basic idea when exporting to plain text output is to find the appropriate pixel/character ratio and convert sizes in the report in order to generate enough space for the exported text. The following parameters and properties are very helpful to accomplish such a task:
The demo/samples/text/reports/TextReport.jrxml template contains an example of report design prepared for the plain text export.
One has to pay attention to the following properties defined in the report: <property name="net.sf.jasperreports.export.text.character.width" value="7.238"/> <property name="net.sf.jasperreports.export.text.character.height" value="13.948"/>They assume that characters are 7.238px wide and 13.948px high. Having a page width of 798px and a page height of 1000px, it follows that pages in the generated text document will count 110 characters per line and 71 lines per page. Also notice that element sizes are set enough large to make room for all their content to be represented in the plain text output. Running the Sample Running the sample requires the Apache Ant library. Make sure that ant is already installed on your system (version 1.5 or later).
In a command prompt/terminal window set the current folder to demo/hsqldb within the JasperReports source project and run the > ant runServer command.
It will start the HSQLDB server shipped with the JasperReports distribution package. Let this terminal running the HSQLDB server.
Open a new command prompt/terminal window and set the current folder to demo/samples/text within the JasperReports source project and run the > ant test view command.
It will generate all supported document types containing the sample report in the demo/samples/text/build/reports directory.
Then the report will open in the JasperReports internal viewer. |
||||
|
|
© 2001- Jaspersoft Corporation www.jaspersoft.com |