public class JRGraphics2DExporter extends JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>
Graphics2D
object.
JasperReports relies on AWT for text measurements and all sorts of layout calculations
during report filling, so documents created using AWT will certainly look perfect when
rendered with AWT on a java.awt.Graphics2D
context. For this reason, the
JRGraphics2DExporter
is the perfect
exporter. The output it produces is considered to be the reference in terms of layout
capabilities and element styling.
Generally speaking, the document quality produced by all the other exporters is only an
approximation of the perfect output that the Graphics2D exporter can produce. As its
name indicates, this exporter is special because it does not produce files or send character
or binary data to an output stream. Instead, its only target for rendering the content of a
page is a java.awt.Graphics2D
object. This exporter is also special because it can
export only one page at a time.
This exporter is used by the built-in Swing viewer to render the content of each page, and
it is also used when printing the documents. The documents are printed page by page,
and the exporter is invoked to draw each document page on the graphic context
associated with the selected printer job.
Because we are relying on the same code (same exporter) when viewing the documents
using the built-in viewer and when printing them, JasperReports is a perfect WYSIWYG
tool. The document quality on paper is the same as on the screen.
In terms of exporter input, note that this exporter does not work in batch mode. If a
java.util.List
of JasperPrint documents is supplied to it through a
SimpleExporterInput
instance, the exporter
considers only the first one for exporting and ignores all the others.
Furthermore, this exporter can export only a single page at a time. The index of the page
to be exported can be set using either the
getStartPageIndex()
exporter configuration setting or the
getPageIndex()
.
Note that if present, getPageIndex()
overrides the value of
getStartPageIndex()
.
Therefore, this exporter actually exports only the first page from
the specified page range, no matter how the page range is specified.
As already mentioned, this exporter needs a target java.awt.Graphics2D
object onto
which to render the specified page. This Graphics2D object can be set using the special
exporter output setting getGraphics2D()
.
If this setting is not present, the exporter will throw an
exception signaling to the caller program that no output target was specified for the
export process.
By default, the exporter renders the content of the page at normal proportions. However,
it can also render it at different proportions if needed. For instance, when used inside the
Swing viewer, the Graphics2D exporter must render the page using the user-defined
zoom ratio. To set the zoom ratio for the exporter, supply a java.lang.Float
value
ranging from 0 to 1 as the value for the
getZoomRatio()
export
configuration setting.
The Graphics2D exporter is also used when printing directly from Java. The Java Print
Service exporter relies on the Graphics2D exporter
and delegates to it all the rendering that needs to be performed on the printer's graphic
context. Some of the existing JVM implementations have problems related to the huge
size of the printer spool jobs that are created even for small documents. To avoid this, a
bug fix was introduced in the Graphics2D exporter to minimize the impact of this
problem and reduce the size of print spool jobs, while preserving document quality when
printing. However, the bug fix itself is not perfect, and users might experience problems
when printing bidirectional writing texts such as Arabic and Hebrew.
This is why the special
isMinimizePrinterJobSize()
export configuration setting was introduced, along with a configuration property called
net.sf.jasperreports.export.graphics2d.min.job.size
, to allow users to turn
on and off this rendering optimization, depending on their actual needs. The
configuration property value is used only in the absence of the export configuration setting.Graphics2DExporterOutput
,
Graphics2DReportConfiguration
,
ReportExportConfiguration
,
SimpleExporterInput
Modifier and Type | Class and Description |
---|---|
protected class |
JRGraphics2DExporter.ExporterContext |
JRAbstractExporter.BaseExporterContext, JRAbstractExporter.PageRange
Modifier and Type | Field and Description |
---|---|
protected PrintDrawVisitor |
drawVisitor |
static String |
GRAPHICS2D_EXPORTER_KEY
The exporter key, as used in
GenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String) . |
static String |
MINIMIZE_PRINTER_JOB_SIZE
Deprecated.
|
allSelector, crtCompositeConfiguration, crtCompositeItemConfiguration, crtItem, dateFormatCache, EXCEPTION_MESSAGE_KEY_END_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_INVALID_IMAGE_NAME, EXCEPTION_MESSAGE_KEY_INVALID_ZOOM_RATIO, EXCEPTION_MESSAGE_KEY_MIXED_CALLS_NOT_ALLOWED, 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, itemConfiguration, jasperPrint, jasperReportsContext, noBackcolorSelector, noneSelector, numberFormatCache, parameters, propertiesUtil, PROPERTY_DEFAULT_FILTER_FACTORY, PROPERTY_SUFFIX_DEFAULT_FILTER_FACTORY, rendererUtil, styledTextUtil, textValueClasses
Constructor and Description |
---|
JRGraphics2DExporter() |
JRGraphics2DExporter(JasperReportsContext jasperReportsContext) |
Modifier and Type | Method and Description |
---|---|
protected void |
ensureOutput() |
protected void |
exportPage(Graphics2D grx,
int pageIndex) |
void |
exportReport()
Performs the export.
|
void |
exportReportToGraphics2D(Graphics2D grx) |
protected Class<Graphics2DExporterConfiguration> |
getConfigurationInterface() |
PrintDrawVisitor |
getDrawVisitor() |
String |
getExporterKey() |
String |
getExporterPropertiesPrefix()
Returns the properties prefix for the current exporter.
|
FrameDrawer |
getFrameDrawer()
Deprecated.
Replaced by
getDrawVisitor() . |
protected Class<Graphics2DReportConfiguration> |
getItemConfigurationInterface() |
protected RenderersCache |
getRenderersCache() |
protected void |
initExport() |
protected void |
initReport() |
createFilter, defaultParseNumber, ensureInput, ensureJasperReportsContext, getBooleanCellValue, getCurrentConfiguration, getCurrentItemConfiguration, getCurrentJasperPrint, getCustomHandler, getDateCellValue, getDateFormat, getExporterContext, getExporterInput, getExporterOutput, getHyperlinkProducer, getJasperReportsContext, getLocale, getNumberCellValue, getNumberFormat, getOffsetX, getOffsetY, getPageRange, getParameter, getParameters, getPropertiesUtil, getRendererUtil, getReportContext, getStyledText, getStyledText, getTextFormatFactoryClass, getTextLocale, getTextTimeZone, getTextValue, getTextValueString, insideFrame, reset, resetClassLoader, resetExportContext, restoreElementOffsets, setClassLoader, setConfiguration, setConfiguration, setCurrentExporterInputItem, setExporterInput, setExporterOutput, setFrameElementsOffset, setJasperPrint, setJasperReportsContext, setOffset, setOffset, setParameter, setParameters, setReportContext
public static final String MINIMIZE_PRINTER_JOB_SIZE
Graphics2DReportConfiguration.MINIMIZE_PRINTER_JOB_SIZE
.public static final String GRAPHICS2D_EXPORTER_KEY
GenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String)
.protected PrintDrawVisitor drawVisitor
public JRGraphics2DExporter() throws JRException
JRException
JRGraphics2DExporter(JasperReportsContext)
public JRGraphics2DExporter(JasperReportsContext jasperReportsContext) throws JRException
JRException
protected Class<Graphics2DExporterConfiguration> getConfigurationInterface()
protected Class<Graphics2DReportConfiguration> getItemConfigurationInterface()
protected void ensureOutput()
public void exportReport() throws JRException
Exporter
exportReport
in interface Exporter<ExporterInput,Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput>
exportReport
in class JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>
JRException
protected void initExport()
protected void initReport()
protected RenderersCache getRenderersCache()
public void exportReportToGraphics2D(Graphics2D grx) throws JRException
JRException
protected void exportPage(Graphics2D grx, int pageIndex) throws JRException
JRException
public String getExporterKey()
public String getExporterPropertiesPrefix()
JRAbstractExporter
getExporterPropertiesPrefix
in class JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>
public PrintDrawVisitor getDrawVisitor()
public FrameDrawer getFrameDrawer()
getDrawVisitor()
.Copyright © 2016. All rights reserved.