net.sf.jasperreports.engine.export

## Class JRGraphics2DExporter

- java.lang.Object
- - net.sf.jasperreports.engine.JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>
  - - net.sf.jasperreports.engine.export.JRGraphics2DExporter

- All Implemented Interfaces:
    JRExporter<ExporterInput,Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput>, Exporter<ExporterInput,Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput>

      public class JRGraphics2DExporter
      extends JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>

  Exports a JasperReports document to a `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.
  Version:
    $Id: JRGraphics2DExporter.java 7063 2014-04-29 09:37:53Z shertage $
  Author:
    Teodor Danciu (teodord@users.sourceforge.net)
  See Also:
    `Graphics2DExporterOutput`, `Graphics2DReportConfiguration`, `ReportExportConfiguration`, `SimpleExporterInput`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and 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 and Description
    --- | ---
    `protected FrameDrawer` | `frameDrawer`
    `static java.lang.String` | `GRAPHICS2D_EXPORTER_KEY` The exporter key, as used in `GenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String)`.
    `static java.lang.String` | `MINIMIZE_PRINTER_JOB_SIZE` Deprecated. Replaced by `Graphics2DReportConfiguration.MINIMIZE_PRINTER_JOB_SIZE`.
    `protected AwtTextRenderer` | `textRenderer`

    - ### Fields inherited from class net.sf.jasperreports.engine.JRAbstractExporter

      `allSelector, crtCompositeConfiguration, crtCompositeItemConfiguration, crtItem, dateFormatCache, EXCEPTION_MESSAGE_KEY_END_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_START_PAGE_INDEX_OUT_OF_RANGE, exporterConfiguration, exporterContext, exporterInput, exporterOutput, filter, itemConfiguration, jasperPrint, jasperReportsContext, noBackcolorSelector, noneSelector, numberFormatCache, parameters, propertiesUtil, PROPERTY_DEFAULT_FILTER_FACTORY, PROPERTY_SUFFIX_DEFAULT_FILTER_FACTORY, styledTextUtil`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JRGraphics2DExporter()`
    `JRGraphics2DExporter(JasperReportsContext jasperReportsContext)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `ensureOutput()`
    `protected void` | `exportPage(java.awt.Graphics2D grx, JRPrintPage page)`
    `void` | `exportReport()` Performs the export.
    `void` | `exportReportToGraphics2D(java.awt.Graphics2D grx)`
    `protected java.lang.Class<Graphics2DExporterConfiguration>` | `getConfigurationInterface()`
    `java.lang.String` | `getExporterKey()`
    `java.lang.String` | `getExporterPropertiesPrefix()` Returns the properties prefix for the current exporter.
    `FrameDrawer` | `getFrameDrawer()`
    `protected java.lang.Class<Graphics2DReportConfiguration>` | `getItemConfigurationInterface()`
    `protected void` | `initExport()`
    `protected void` | `initReport()`

    - ### Methods inherited from class net.sf.jasperreports.engine.JRAbstractExporter

      `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, getReportContext, getStyledText, getStyledText, getTextFormatFactoryClass, getTextLocale, getTextTimeZone, getTextValue, getTextValueString, reset, resetClassLoader, resetExportContext, restoreElementOffsets, setClassLoader, setConfiguration, setConfiguration, setCurrentExporterInputItem, setExporterInput, setExporterOutput, setFrameElementsOffset, setJasperPrint, setJasperReportsContext, setOffset, setOffset, setParameter, setParameters, setReportContext`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### MINIMIZE_PRINTER_JOB_SIZE

          public static final java.lang.String MINIMIZE_PRINTER_JOB_SIZE

      Deprecated. Replaced by `Graphics2DReportConfiguration.MINIMIZE_PRINTER_JOB_SIZE`.
      See Also:
        Constant Field Values

    - #### GRAPHICS2D_EXPORTER_KEY

          public static final java.lang.String GRAPHICS2D_EXPORTER_KEY

      The exporter key, as used in `GenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String)`.
      See Also:
        Constant Field Values

    - #### textRenderer

          protected AwtTextRenderer textRenderer

    - #### frameDrawer

          protected FrameDrawer frameDrawer

  - ### 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 java.lang.Class<Graphics2DExporterConfiguration> getConfigurationInterface()

      Specified by:
        `getConfigurationInterface` in class `JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>`

    - #### getItemConfigurationInterface

          protected java.lang.Class<Graphics2DReportConfiguration> getItemConfigurationInterface()

      Specified by:
        `getItemConfigurationInterface` in class `JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>`

    - #### ensureOutput

          protected void ensureOutput()

      Specified by:
        `ensureOutput` in class `JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>`

    - #### exportReport

          public void exportReport()
                            throws JRException

      Description copied from interface: `Exporter`
      Performs the export.
      Specified by:
        `exportReport` in interface `Exporter<ExporterInput,Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput>`
      Specified by:
        `exportReport` in class `JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>`
      Throws:
        `JRException`

    - #### initExport

          protected void initExport()

      Overrides:
        `initExport` in class `JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>`

    - #### initReport

          protected void initReport()

      Overrides:
        `initReport` in class `JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>`

    - #### exportReportToGraphics2D

          public void exportReportToGraphics2D(java.awt.Graphics2D grx)
                                        throws JRException

      Throws:
        `JRException`

    - #### exportPage

          protected void exportPage(java.awt.Graphics2D grx,
                        JRPrintPage page)
                             throws JRException

      Throws:
        `JRException`

    - #### getExporterKey

          public java.lang.String getExporterKey()

      Specified by:
        `getExporterKey` in class `JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>`

    - #### getExporterPropertiesPrefix

          public java.lang.String getExporterPropertiesPrefix()

      Description copied from class: `JRAbstractExporter`
      Returns the properties prefix for the current exporter.
      Specified by:
        `getExporterPropertiesPrefix` in class `JRAbstractExporter<Graphics2DReportConfiguration,Graphics2DExporterConfiguration,Graphics2DExporterOutput,JRGraphics2DExporterContext>`
      Returns:
        the properties prefix for the current exporter

    - #### getFrameDrawer

          public FrameDrawer getFrameDrawer()

      Returns:
        the frameDrawer

© 2001-2010 Jaspersoft Corporation www.jaspersoft.com