Class JRTextExporter
java.lang.Object
net.sf.jasperreports.engine.JRAbstractExporter<TextReportConfiguration,TextExporterConfiguration,WriterExporterOutput,JRTextExporterContext>
net.sf.jasperreports.engine.export.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
):
getCharWidth()
andgetCharHeight()
- these specify how many pixels in the original report should be mapped onto a character in the exported text.getPageWidthInChars()
andgetPageHeightInChars()
- these specify the text page width and height in characters.
- 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.
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:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class net.sf.jasperreports.engine.JRAbstractExporter
JRAbstractExporter.BaseExporterContext, JRAbstractExporter.PageRange
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected float
protected float
static final String
static final String
static final String
static final String
protected boolean
protected String
protected int
protected String
protected int
protected static final String
protected Writer
Fields inherited from class net.sf.jasperreports.engine.JRAbstractExporter
allSelector, crtCompositeConfiguration, crtCompositeItemConfiguration, crtItem, dateFormatCache, EXCEPTION_MESSAGE_KEY_EMPTY_INPUT_SOURCE_IN_BATCH_MODE, EXCEPTION_MESSAGE_KEY_END_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_INVALID_IMAGE_NAME, EXCEPTION_MESSAGE_KEY_INVALID_ZOOM_RATIO, EXCEPTION_MESSAGE_KEY_NO_INPUT_SOURCE, EXCEPTION_MESSAGE_KEY_NO_OUTPUT_SPECIFIED, EXCEPTION_MESSAGE_KEY_OUTPUT_WRITER_ERROR, EXCEPTION_MESSAGE_KEY_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_START_PAGE_INDEX_OUT_OF_RANGE, exporterConfiguration, exporterContext, exporterInput, exporterOutput, filter, fontUtil, hyperlinkProducerFactory, itemConfiguration, jasperPrint, jasperReportsContext, noBackcolorSelector, noneSelector, numberFormatCache, propertiesUtil, PROPERTY_DEFAULT_FILTER_FACTORY, PROPERTY_SUFFIX_DEFAULT_FILTER_FACTORY, rendererUtil, styledTextUtil, textValueClasses
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
exportElements
(List<JRPrintElement> elements) protected void
exportPage
(JRPrintPage page) Exports a page to the output writer.void
Performs the export.protected void
protected void
exportText
(JRPrintText element) Renders a text and places it in the output matrix.protected Class
<TextExporterConfiguration> Returns the properties prefix for the current exporter.protected int
getHeightInChars
(int height) Transforms height from pixel space to character space.protected Class
<TextReportConfiguration> protected JRStyledText
getStyledText
(JRPrintText textElement) protected int
getWidthInChars
(int width) Transforms width from pixel space to character space.protected void
protected void
Methods inherited from class net.sf.jasperreports.engine.JRAbstractExporter
checkInterrupted, createFilter, defaultParseNumber, ensureInput, ensureJasperReportsContext, ensureOutput, getBooleanCellValue, getCurrentConfiguration, getCurrentItemConfiguration, getCurrentJasperPrint, getDateCellValue, getDateFormat, getExporterConfiguration, getExporterContext, getExporterInput, getExporterOutput, getHyperlinkProducer, getJasperReportsContext, getLocale, getNumberCellValue, getNumberFormat, getOffsetX, getOffsetY, getPageRange, getPropertiesUtil, getRendererUtil, getReportContext, getReportExportConfiguration, getRepository, getStyledText, getTextFormatFactoryClass, getTextLocale, getTextTimeZone, getTextValue, getTextValueString, insideFrame, reset, resetExportContext, restoreElementOffsets, setConfiguration, setConfiguration, setCurrentExporterInputItem, setExporterInput, setExporterOutput, setFrameElementsOffset, setJasperReportsContext, setOffset, setOffset, setReportContext
-
Field Details
-
EXCEPTION_MESSAGE_KEY_REQUIRED_POSITIVE_PAGE_OR_CHARACTER_WIDTH
- See Also:
-
EXCEPTION_MESSAGE_KEY_CHARACTER_WIDTH_NEGATIVE
- See Also:
-
EXCEPTION_MESSAGE_KEY_REQUIRED_POSITIVE_PAGE_OR_CHARACTER_HEIGHT
- See Also:
-
EXCEPTION_MESSAGE_KEY_CHARACTER_HEIGHT_NEGATIVE
- See Also:
-
writer
-
pageWidthInChars
protected int pageWidthInChars -
pageHeightInChars
protected int pageHeightInChars -
charWidth
protected float charWidth -
charHeight
protected float charHeight -
pageSeparator
-
lineSeparator
-
isTrimLineRight
protected boolean isTrimLineRight -
systemLineSeparator
-
-
Constructor Details
-
JRTextExporter
public JRTextExporter()- See Also:
-
JRTextExporter
-
-
Method Details
-
getConfigurationInterface
-
getItemConfigurationInterface
-
exportReport
Description copied from interface:Exporter
Performs the export.- Specified by:
exportReport
in interfaceExporter<ExporterInput,
TextReportConfiguration, TextExporterConfiguration, WriterExporterOutput> - Specified by:
exportReport
in classJRAbstractExporter<TextReportConfiguration,
TextExporterConfiguration, WriterExporterOutput, JRTextExporterContext> - Throws:
JRException
-
initExport
protected void initExport() -
initReport
protected void initReport() -
exportReportToWriter
- Throws:
JRException
IOException
-
exportPage
Exports a page to the output writer. Only text elements within the page are considered. For each page, the engine creates a matrix of characters and each rendered text element is placed at the appropriate position in the matrix. After all texts are parsed, the character matrix is sent to the output writer.- Throws:
IOException
-
exportElements
-
exportText
Renders a text and places it in the output matrix. -
getHeightInChars
protected int getHeightInChars(int height) Transforms height from pixel space to character space. -
getWidthInChars
protected int getWidthInChars(int width) Transforms width from pixel space to character space. -
getStyledText
-
getExporterKey
-
getExporterPropertiesPrefix
Description copied from class:JRAbstractExporter
Returns the properties prefix for the current exporter.- Specified by:
getExporterPropertiesPrefix
in classJRAbstractExporter<TextReportConfiguration,
TextExporterConfiguration, WriterExporterOutput, JRTextExporterContext> - Returns:
- the properties prefix for the current exporter
-