Class JRTextExporter

  • All Implemented Interfaces:
    Exporter<ExporterInput,​TextReportConfiguration,​TextExporterConfiguration,​WriterExporterOutput>

    public class JRTextExporter
    extends JRAbstractExporter<TextReportConfiguration,​TextExporterConfiguration,​WriterExporterOutput,​JRTextExporterContext>
    Exports filled reports in plain text format. The text exporter allows users to define a custom character resolution (the number of columns and rows in text format). Since the character resolution is mapped on the actual pixel resolution, every character corresponds to a rectangle of pixels. If a certain text element has a smaller size in pixels (width, height, or both) than the number of pixels that map to a character, the text element will not be rendered.

    The text exporter will yield the better results if the space needed for displaying a text is large. So users have to either design reports with few text or export to big text pages. Another good practice is to arrange text elements at design time as similar as possible to a grid.

    The text exporter tries to convert the JasperReports document into a simple text document with a fixed page width and height, measured in characters. Users can specify the desired page width and height, and the engine will make the best effort to fit text elements into the corresponding text page. The basic idea of the algorithm is to convert pixels to characters (to find a pixel/character ratio). To achieve this, use the following configuration settings (see TextReportConfiguration):

    Note that both width and height must be specified and that character sizes have priority over page sizes.

    Since the algorithm causes loss of precision, a few precautions should be taken when creating templates that will eventually be exported to plain text:

    • Report sizes and text page sizes should be divisible (for example, specify a template width of 1,000 pixels and a page width of 100 characters, resulting in a character width of 10 pixels).
    • Text element sizes should also follow the preceding rule (for example, if the character height is 10 pixels and a particular text element is expected to span two rows, then the text element should be 20 pixels tall).
    • For best results, text elements should be aligned in a grid-like fashion.
    • Text fields should not be too small. Following are two examples of problems that this can cause:
      • If the element height is smaller than the character height, then the element will not appear in the exported text file.
      • If the character width is 10 and the element width is 80, then only the first eight characters will be displayed.

    Users can specify the text that should be inserted between two subsequent pages by using the getPageSeparator() exporter configuration setting. The default value is two blank lines.

    The line separator to be used in the generated text file can be specified using the getLineSeparator() exporter configuration setting. This is most useful when you want to force a particular line separator, knowing that the default line separator is operating system dependent, as specified by the line.separator system property of the JVM.

    Check the supplied /demo/samples/text sample to see the kind of output this exporter can produce.

    Author:
    Ionut Nedelcu (ionutned@users.sourceforge.net)
    See Also:
    TextExporterConfiguration, TextReportConfiguration