Class JRGraphics2DExporter
- java.lang.Object
-
- net.sf.jasperreports.engine.JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>
-
- net.sf.jasperreports.engine.export.JRGraphics2DExporter
-
- All Implemented Interfaces:
Exporter<ExporterInput,Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput>
public class JRGraphics2DExporter extends JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>
Exports a JasperReports document to aGraphics2D
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 ajava.awt.Graphics2D
context. For this reason, theJRGraphics2DExporter
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 ajava.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 ajava.util.List
of JasperPrint documents is supplied to it through aSimpleExporterInput
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 thegetStartPageIndex()
exporter configuration setting or thegetPageIndex()
. Note that if present,getPageIndex()
overrides the value ofgetStartPageIndex()
. 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 targetjava.awt.Graphics2D
object onto which to render the specified page. This Graphics2D object can be set using the special exporter output settinggetGraphics2D()
. 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 ajava.lang.Float
value ranging from 0 to 1 as the value for thegetZoomRatio()
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 specialisMinimizePrinterJobSize()
export configuration setting was introduced, along with a configuration property callednet.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.- Author:
- Teodor Danciu (teodord@users.sourceforge.net)
- See Also:
Graphics2DExporterOutput
,Graphics2DReportConfiguration
,ReportExportConfiguration
,SimpleExporterInput
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
JRGraphics2DExporter.ExporterContext
-
Nested classes/interfaces inherited from class net.sf.jasperreports.engine.JRAbstractExporter
JRAbstractExporter.BaseExporterContext, JRAbstractExporter.PageRange
-
-
Field Summary
Fields Modifier and Type Field Description protected PrintDrawVisitor
drawVisitor
static String
GRAPHICS2D_EXPORTER_KEY
The exporter key, as used inGenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String)
.-
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 Constructor Description JRGraphics2DExporter()
JRGraphics2DExporter(JasperReportsContext jasperReportsContext)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.protected Class<Graphics2DReportConfiguration>
getItemConfigurationInterface()
protected RenderersCache
getRenderersCache()
protected void
initExport()
protected void
initReport()
-
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, getStyledText, getTextFormatFactoryClass, getTextLocale, getTextTimeZone, getTextValue, getTextValueString, insideFrame, reset, resetExportContext, restoreElementOffsets, setConfiguration, setConfiguration, setCurrentExporterInputItem, setExporterInput, setExporterOutput, setFrameElementsOffset, setJasperReportsContext, setOffset, setOffset, setReportContext
-
-
-
-
Field Detail
-
GRAPHICS2D_EXPORTER_KEY
public static final String GRAPHICS2D_EXPORTER_KEY
The exporter key, as used inGenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String)
.- See Also:
- Constant Field Values
-
drawVisitor
protected PrintDrawVisitor drawVisitor
-
-
Constructor Detail
-
JRGraphics2DExporter
public JRGraphics2DExporter() throws JRException
- Throws:
JRException
- See Also:
JRGraphics2DExporter(JasperReportsContext)
-
JRGraphics2DExporter
public JRGraphics2DExporter(JasperReportsContext jasperReportsContext) throws JRException
- Throws:
JRException
-
-
Method Detail
-
getConfigurationInterface
protected Class<Graphics2DExporterConfiguration> getConfigurationInterface()
-
getItemConfigurationInterface
protected Class<Graphics2DReportConfiguration> getItemConfigurationInterface()
-
exportReport
public void exportReport() throws JRException
Description copied from interface:Exporter
Performs the export.- Specified by:
exportReport
in interfaceExporter<ExporterInput,Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput>
- Specified by:
exportReport
in classJRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>
- Throws:
JRException
-
initExport
protected void initExport()
-
initReport
protected void initReport()
-
getRenderersCache
protected RenderersCache getRenderersCache()
-
exportReportToGraphics2D
public void exportReportToGraphics2D(Graphics2D grx) throws JRException
- Throws:
JRException
-
exportPage
protected void exportPage(Graphics2D grx, int pageIndex) throws JRException
- Throws:
JRException
-
getExporterKey
public String getExporterKey()
-
getExporterPropertiesPrefix
public String getExporterPropertiesPrefix()
Description copied from class:JRAbstractExporter
Returns the properties prefix for the current exporter.- Specified by:
getExporterPropertiesPrefix
in classJRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>
- Returns:
- the properties prefix for the current exporter
-
getDrawVisitor
public PrintDrawVisitor getDrawVisitor()
-
-