org.apache.fop.render.afp

## Class AFPDocumentHandler

- java.lang.Object
- - org.apache.fop.render.intermediate.AbstractIFDocumentHandler
  - - org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler
    - - org.apache.fop.render.afp.AFPDocumentHandler

- All Implemented Interfaces:
    AFPCustomizable, IFDocumentHandler

      public class AFPDocumentHandler
      extends AbstractBinaryWritingIFDocumentHandler
      implements AFPCustomizable

  `IFDocumentHandler` implementation that produces AFP (MO:DCA).

- - ### Field Summary

    - ### Fields inherited from class org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler

      `fontInfo, outputStream`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AFPDocumentHandler(IFContext context)` Default constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `cacheRoundedCorner(String cornerKey)` Corner images can be reused by storing at the document level in the AFP The cache is used to map cahced images to caller generated descriptions of the corner
    `void` | `canEmbedJpeg(boolean canEmbed)` Sets whether or not to JPEG images can be embedded in the AFP document.
    `void` | `endDocument()` Indicates the end of a document.
    `void` | `endDocumentHeader()` Indicates the end of the document header.
    `void` | `endPage()` Indicates the end of a page
    `void` | `endPageContent()` Indicates the end of the page content.
    `void` | `endPageHeader()` Indicates the end of the page header.
    `void` | `endPageSequence()` Indicates the end of a page sequence.
    `String` | `getCachedRoundedCorner(String cornerKey)` This method returns the an id that identifies a cached corner or null if non existent
    `IFDocumentHandlerConfigurator` | `getConfigurator()` Returns the configurator for this document handler, if any.
    `boolean` | `getFS45()` gets whether images should be FS45
    `String` | `getMimeType()` Returns the MIME type of the output format that is generated by this implementation.
    `int` | `getResolution()` Returns the output/device resolution.
    `boolean` | `getWrapPSeg()` gets whether FS11 and FS45 non-inline images should be wrapped in a page segment
    `void` | `handleExtensionObject(Object extension)` Handles an extension object.
    `boolean` | `isGOCAEnabled()` Indicates whether GOCA is enabled or disabled.
    `boolean` | `isStrokeGOCAText()` Indicates whether to stroke text in GOCA mode or to use text operators where possible.
    `void` | `setBitmapEncodingQuality(float quality)` Sets the image encoding quality setting to use when encoding bitmap images.
    `void` | `setBitsPerPixel(int bitsPerPixel)` Sets the number of bits used per pixel
    `void` | `setCMYKImagesSupported(boolean value)` Controls whether CMYK images (IOCA FS45) are enabled.
    `void` | `setColorImages(boolean colorImages)` Sets whether images are color or not
    `void` | `setDefaultFontInfo(FontInfo fontInfo)` Sets the default font set (with no custom configuration).
    `void` | `setDefaultResourceGroupUri(URI uri)` Sets the default resource group URI
    `void` | `setDitheringQuality(float quality)` Sets the dithering quality setting to use when converting images to monochrome images.
    `void` | `setFS45(boolean fs45)` set true if images should be FS45
    `void` | `setGOCAEnabled(boolean enabled)` Controls whether GOCA is enabled or disabled.
    `void` | `setLineWidthCorrection(float correction)` Sets the line width correction
    `void` | `setMaskEnabled(boolean maskEnabled)`
    `void` | `setNativeImagesSupported(boolean nativeImages)` Sets whether images are supported natively or not
    `void` | `setNativePDFImagesSupported(boolean nativeImages)`
    `void` | `setResolution(int resolution)` Sets the output/device resolution
    `void` | `setResourceLevelDefaults(AFPResourceLevelDefaults defaults)` Sets the resource level defaults.
    `void` | `setShadingMode(AFPShadingMode shadingMode)` Sets the shading mode for painting filled rectangles.
    `void` | `setStrokeGOCAText(boolean stroke)` Controls whether to stroke text in GOCA mode or to use text operators where possible.
    `void` | `setUseIocaImages(boolean useIocaImages)`
    `void` | `setWrapGocaPSeg(boolean pSeg)`
    `void` | `setWrapPSeg(boolean pSeg)` Sets whether FS11 and FS45 non-inline images should be wrapped in a page segment
    `void` | `startDocument()` Indicates the start of a document.
    `void` | `startDocumentHeader()` Indicates the start of the document header.
    `void` | `startPage(int index, String name, String pageMasterName, Dimension size)` Indicates the start of a new page.
    `IFPainter` | `startPageContent()` Indicates the start of the page content.
    `void` | `startPageHeader()` Indicates the start of the page header.
    `void` | `startPageSequence(String id)` Indicates the start of a new page sequence.
    `boolean` | `supportsPagesOutOfOrder()` Indicates whether the painter supports to handle the pages in mixed order rather than ascending order.

    - ### Methods inherited from class org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler

      `getFontInfo, setFontInfo, setResult`

    - ### Methods inherited from class org.apache.fop.render.intermediate.AbstractIFDocumentHandler

      `endDocumentTrailer, endPageTrailer, getContext, getDocumentNavigationHandler, getStructureTreeEventHandler, getUserAgent, setDocumentLocale, startDocumentTrailer, startPageTrailer`

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

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

- - ### Constructor Detail

    - #### AFPDocumentHandler

          public AFPDocumentHandler(IFContext context)

      Default constructor.

  - ### Method Detail

    - #### supportsPagesOutOfOrder

          public boolean supportsPagesOutOfOrder()

      Indicates whether the painter supports to handle the pages in mixed order rather than ascending order.
      Specified by:
        `supportsPagesOutOfOrder` in interface `IFDocumentHandler`
      Returns:
        true if out-of-order handling is supported

    - #### getMimeType

          public String getMimeType()

      Returns the MIME type of the output format that is generated by this implementation.
      Specified by:
        `getMimeType` in interface `IFDocumentHandler`
      Returns:
        the MIME type

    - #### getConfigurator

          public IFDocumentHandlerConfigurator getConfigurator()

      Returns the configurator for this document handler, if any.
      Specified by:
        `getConfigurator` in interface `IFDocumentHandler`
      Returns:
        the configurator or null if there's no configurator

    - #### setDefaultFontInfo

          public void setDefaultFontInfo(FontInfo fontInfo)

      Sets the default font set (with no custom configuration).
      Specified by:
        `setDefaultFontInfo` in interface `IFDocumentHandler`
      Overrides:
        `setDefaultFontInfo` in class `AbstractBinaryWritingIFDocumentHandler`
      Parameters:
        `fontInfo` - the font info object to populate

    - #### startDocument

          public void startDocument()
                             throws IFException

      Indicates the start of a document. This method may only be called once before any other event method.
      Specified by:
        `startDocument` in interface `IFDocumentHandler`
      Overrides:
        `startDocument` in class `AbstractBinaryWritingIFDocumentHandler`
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### startDocumentHeader

          public void startDocumentHeader()
                                   throws IFException

      Indicates the start of the document header. This method is called right after the `IFDocumentHandler.startDocument()` method. Extensions sent to this painter between `IFDocumentHandler.startDocumentHeader()` and `IFDocumentHandler.endDocumentHeader()` apply to the document as a whole (like document metadata).
      Specified by:
        `startDocumentHeader` in interface `IFDocumentHandler`
      Overrides:
        `startDocumentHeader` in class `AbstractIFDocumentHandler`
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### endDocumentHeader

          public void endDocumentHeader()
                                 throws IFException

      Indicates the end of the document header. This method is called before the first page sequence.
      Specified by:
        `endDocumentHeader` in interface `IFDocumentHandler`
      Overrides:
        `endDocumentHeader` in class `AbstractIFDocumentHandler`
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### endDocument

          public void endDocument()
                           throws IFException

      Indicates the end of a document. This method may only be called once after the whole document has been handled. Implementations can release resources (close streams). It is an error to call any event method after this method.
      Specified by:
        `endDocument` in interface `IFDocumentHandler`
      Overrides:
        `endDocument` in class `AbstractBinaryWritingIFDocumentHandler`
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### startPageSequence

          public void startPageSequence(String id)
                                 throws IFException

      Indicates the start of a new page sequence.
      Specified by:
        `startPageSequence` in interface `IFDocumentHandler`
      Parameters:
        `id` - the page sequence's identifier (or null if none is available)
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### endPageSequence

          public void endPageSequence()
                               throws IFException

      Indicates the end of a page sequence.
      Specified by:
        `endPageSequence` in interface `IFDocumentHandler`
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### startPage

          public void startPage(int index,
                                String name,
                                String pageMasterName,
                                Dimension size)
                         throws IFException

      Indicates the start of a new page.
      Specified by:
        `startPage` in interface `IFDocumentHandler`
      Parameters:
        `index` - the index of the page (0-based)
        `name` - the page name (usually the formatted page number)
        `pageMasterName` - the name of the simple-page-master that generated this page
        `size` - the size of the page (equivalent to the MediaBox in PDF)
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### startPageHeader

          public void startPageHeader()
                               throws IFException

      Indicates the start of the page header.
      Specified by:
        `startPageHeader` in interface `IFDocumentHandler`
      Overrides:
        `startPageHeader` in class `AbstractIFDocumentHandler`
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### endPageHeader

          public void endPageHeader()
                             throws IFException

      Indicates the end of the page header.
      Specified by:
        `endPageHeader` in interface `IFDocumentHandler`
      Overrides:
        `endPageHeader` in class `AbstractIFDocumentHandler`
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### startPageContent

          public IFPainter startPageContent()
                                     throws IFException

      Indicates the start of the page content. The method returns an `IFPainter` interface which is used to paint the page contents.
      Specified by:
        `startPageContent` in interface `IFDocumentHandler`
      Returns:
        the IFPainter for the page content
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### endPageContent

          public void endPageContent()
                              throws IFException

      Indicates the end of the page content. Calls to the `IFPainter` returned by the respective `IFDocumentHandler.startPageContent()` method are illegal.
      Specified by:
        `endPageContent` in interface `IFDocumentHandler`
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### endPage

          public void endPage()
                       throws IFException

      Indicates the end of a page
      Specified by:
        `endPage` in interface `IFDocumentHandler`
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### handleExtensionObject

          public void handleExtensionObject(Object extension)
                                     throws IFException

      Handles an extension object. This can be a DOM document or any arbitrary object. If an implementation doesn't know how to handle a particular extension it is simply ignored.
      Specified by:
        `handleExtensionObject` in interface `IFDocumentHandler`
      Parameters:
        `extension` - the extension object
      Throws:
        `IFException` - if an error occurs while handling this event

    - #### cacheRoundedCorner

          public String cacheRoundedCorner(String cornerKey)

      Corner images can be reused by storing at the document level in the AFP The cache is used to map cahced images to caller generated descriptions of the corner
      Parameters:
        `cornerKey` - caller's identifier for the corner
      Returns:
        document id of the corner image

    - #### getCachedRoundedCorner

          public String getCachedRoundedCorner(String cornerKey)

      This method returns the an id that identifies a cached corner or null if non existent
      Parameters:
        `cornerKey` - caller's identifier for the corner
      Returns:
        document id of the corner image

    - #### setBitsPerPixel

          public void setBitsPerPixel(int bitsPerPixel)

      Sets the number of bits used per pixel
      Specified by:
        `setBitsPerPixel` in interface `AFPCustomizable`
      Parameters:
        `bitsPerPixel` - number of bits per pixel

    - #### setColorImages

          public void setColorImages(boolean colorImages)

      Sets whether images are color or not
      Specified by:
        `setColorImages` in interface `AFPCustomizable`
      Parameters:
        `colorImages` - color image output

    - #### setNativeImagesSupported

          public void setNativeImagesSupported(boolean nativeImages)

      Sets whether images are supported natively or not
      Specified by:
        `setNativeImagesSupported` in interface `AFPCustomizable`
      Parameters:
        `nativeImages` - native image support

    - #### setNativePDFImagesSupported

          public void setNativePDFImagesSupported(boolean nativeImages)

    - #### setCMYKImagesSupported

          public void setCMYKImagesSupported(boolean value)

      Controls whether CMYK images (IOCA FS45) are enabled. By default, support is disabled for wider compatibility. When disabled, any CMYK image is converted to the selected color format.
      Specified by:
        `setCMYKImagesSupported` in interface `AFPCustomizable`
      Parameters:
        `value` - true to enabled CMYK images

    - #### setDitheringQuality

          public void setDitheringQuality(float quality)

      Sets the dithering quality setting to use when converting images to monochrome images.
      Specified by:
        `setDitheringQuality` in interface `AFPCustomizable`
      Parameters:
        `quality` - Defines the desired quality level for the conversion. Valid values: a value between 0.0f (fastest) and 1.0f (best)

    - #### setBitmapEncodingQuality

          public void setBitmapEncodingQuality(float quality)

      Sets the image encoding quality setting to use when encoding bitmap images. The default setting is 1.0 which means loss-less encoding. Settings of less than 1.0 allow loss-less encoding schemes like JPEG. The value serves as quality setting for the encoders in that case.
      Specified by:
        `setBitmapEncodingQuality` in interface `AFPCustomizable`
      Parameters:
        `quality` - Defines the desired quality level. Valid values: a value between 0.0f (lowest) and 1.0f (best, loss-less)

    - #### setUseIocaImages

          public void setUseIocaImages(boolean useIocaImages)

    - #### setShadingMode

          public void setShadingMode(AFPShadingMode shadingMode)

      Sets the shading mode for painting filled rectangles.
      Specified by:
        `setShadingMode` in interface `AFPCustomizable`
      Parameters:
        `shadingMode` - the shading mode

    - #### setResolution

          public void setResolution(int resolution)

      Sets the output/device resolution
      Specified by:
        `setResolution` in interface `AFPCustomizable`
      Parameters:
        `resolution` - the output resolution (dpi)

    - #### setLineWidthCorrection

          public void setLineWidthCorrection(float correction)

      Sets the line width correction
      Specified by:
        `setLineWidthCorrection` in interface `AFPCustomizable`
      Parameters:
        `correction` - the line width multiplying factor correction

    - #### getResolution

          public int getResolution()

      Returns the output/device resolution.
      Specified by:
        `getResolution` in interface `AFPCustomizable`
      Returns:
        the resolution in dpi

    - #### setGOCAEnabled

          public void setGOCAEnabled(boolean enabled)

      Controls whether GOCA is enabled or disabled.
      Specified by:
        `setGOCAEnabled` in interface `AFPCustomizable`
      Parameters:
        `enabled` - true if GOCA is enabled, false if it is disabled

    - #### isGOCAEnabled

          public boolean isGOCAEnabled()

      Indicates whether GOCA is enabled or disabled.
      Specified by:
        `isGOCAEnabled` in interface `AFPCustomizable`
      Returns:
        true if GOCA is enabled, false if GOCA is disabled

    - #### setStrokeGOCAText

          public void setStrokeGOCAText(boolean stroke)

      Controls whether to stroke text in GOCA mode or to use text operators where possible.
      Specified by:
        `setStrokeGOCAText` in interface `AFPCustomizable`
      Parameters:
        `stroke` - true to stroke, false to paint with text operators where possible

    - #### isStrokeGOCAText

          public boolean isStrokeGOCAText()

      Indicates whether to stroke text in GOCA mode or to use text operators where possible.
      Specified by:
        `isStrokeGOCAText` in interface `AFPCustomizable`
      Returns:
        true to stroke, false to paint with text operators where possible

    - #### setWrapPSeg

          public void setWrapPSeg(boolean pSeg)

      Sets whether FS11 and FS45 non-inline images should be wrapped in a page segment
      Specified by:
        `setWrapPSeg` in interface `AFPCustomizable`
      Parameters:
        `pSeg` - true iff images should be wrapped

    - #### setWrapGocaPSeg

          public void setWrapGocaPSeg(boolean pSeg)

    - #### setFS45

          public void setFS45(boolean fs45)

      set true if images should be FS45
      Specified by:
        `setFS45` in interface `AFPCustomizable`
      Parameters:
        `fs45` - true iff images should be FS45

    - #### setMaskEnabled

          public void setMaskEnabled(boolean maskEnabled)

    - #### getWrapPSeg

          public boolean getWrapPSeg()

      gets whether FS11 and FS45 non-inline images should be wrapped in a page segment
      Specified by:
        `getWrapPSeg` in interface `AFPCustomizable`
      Returns:
        true iff images should be wrapped

    - #### getFS45

          public boolean getFS45()

      gets whether images should be FS45
      Specified by:
        `getFS45` in interface `AFPCustomizable`
      Returns:
        true iff images should be FS45

    - #### setDefaultResourceGroupUri

          public void setDefaultResourceGroupUri(URI uri)

      Description copied from interface: `AFPCustomizable`
      Sets the default resource group URI
      Specified by:
        `setDefaultResourceGroupUri` in interface `AFPCustomizable`
      Parameters:
        `uri` - the default resource group URI

    - #### setResourceLevelDefaults

          public void setResourceLevelDefaults(AFPResourceLevelDefaults defaults)

      Sets the resource level defaults. The object passed in provides information which resource level shall be used by default for various kinds of resources.
      Specified by:
        `setResourceLevelDefaults` in interface `AFPCustomizable`
      Parameters:
        `defaults` - the resource level defaults

    - #### canEmbedJpeg

          public void canEmbedJpeg(boolean canEmbed)

      Sets whether or not to JPEG images can be embedded in the AFP document.
      Specified by:
        `canEmbedJpeg` in interface `AFPCustomizable`
      Parameters:
        `canEmbed` - whether or not to embed JPEG image

Copyright © 2025 Apache Software Foundation. All rights reserved.