org.apache.fop.pdf

## Class BitmapImage

- java.lang.Object
- - org.apache.fop.pdf.BitmapImage

- All Implemented Interfaces:
    PDFImage

      public class BitmapImage
      extends Object
      implements PDFImage

  Bitmap image. This is used to create a bitmap image that will be inserted into pdf.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BitmapImage(String k, int width, int height, byte[] data, PDFReference mask)` Create a bitmap image.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `disallowMultipleFilters()` Disallows multiple filters.
    `int` | `getBitsPerComponent()` Get the bits per color component for this image.
    `PDFDeviceColorSpace` | `getColorSpace()` Get the color space for the image data.
    `String` | `getFilterHint()` Returns a hint in form of a String (Possible values from PDFFilterList) indicating which filter setup should be used to encode the object.
    `int` | `getHeight()` Get the height of this image.
    `PDFICCStream` | `getICCStream()` Get the ICC stream.
    `String` | `getKey()` Get the key for this image.
    `String` | `getMask()` Get the bitmap mask reference for this image.
    `PDFFilter` | `getPDFFilter()` Get the PDF Filter to be applied to the image.
    `PDFReference` | `getSoftMaskReference()` Get the PDF reference for a soft mask.
    `PDFColor` | `getTransparentColor()` Get the transparent color for this image.
    `int` | `getWidth()` Get the width of this image.
    `boolean` | `isInverted()`
    `boolean` | `isPS()` Check if this is a postscript image.
    `boolean` | `isTransparent()` Check if this image has a transparent color.
    `boolean` | `multipleFiltersAllowed()` Indicates whether multiple image filters are allowed; this is implemented because Adobe Reader does not like multiple FlateDecode filters applied to an image even though that allowed by the PDF spec; this is probable due to security concerns since many PDF malware exploits, like zip bombs, make use of a chain of FlateDecode filters.
    `void` | `outputContents(OutputStream out)` Writes the raw, unencoded contents of the image to a given output stream.
    `void` | `populateXObjectDictionary(PDFDictionary dict)` Populates the XObject's dictionary with additional values.
    `void` | `setColorSpace(PDFDeviceColorSpace cs)` Set the color space for this image.
    `void` | `setPDFFilter(PDFFilter pdfFilter)`
    `void` | `setTransparent(PDFColor t)` Set the transparent color for this iamge.
    `void` | `setup(PDFDocument doc)` Setup this image with the pdf document.

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

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

- - ### Constructor Detail

    - #### BitmapImage

          public BitmapImage(String k,
                             int width,
                             int height,
                             byte[] data,
                             PDFReference mask)

      Create a bitmap image. Creates a new bitmap image with the given data.
      Parameters:
        `k` - the key to be used to lookup the image
        `width` - the width of the image
        `height` - the height of the image
        `data` - the bitmap data
        `mask` - the transparency mask reference if any

  - ### Method Detail

    - #### setup

          public void setup(PDFDocument doc)

      Setup this image with the pdf document.
      Specified by:
        `setup` in interface `PDFImage`
      Parameters:
        `doc` - the pdf document this will be inserted into

    - #### getKey

          public String getKey()

      Get the key for this image. This key is used by the pdf document so that it will only insert an image once. All other references to the same image will use the same XObject reference.
      Specified by:
        `getKey` in interface `PDFImage`
      Returns:
        the unique key to identify this image

    - #### getWidth

          public int getWidth()

      Get the width of this image.
      Specified by:
        `getWidth` in interface `PDFImage`
      Returns:
        the width of the image

    - #### getHeight

          public int getHeight()

      Get the height of this image.
      Specified by:
        `getHeight` in interface `PDFImage`
      Returns:
        the height of the image

    - #### setColorSpace

          public void setColorSpace(PDFDeviceColorSpace cs)

      Set the color space for this image.
      Parameters:
        `cs` - the pdf color space

    - #### getColorSpace

          public PDFDeviceColorSpace getColorSpace()

      Get the color space for the image data. Possible options are: DeviceGray, DeviceRGB, or DeviceCMYK
      Specified by:
        `getColorSpace` in interface `PDFImage`
      Returns:
        the pdf doclor space

    - #### getBitsPerComponent

          public int getBitsPerComponent()

      Get the bits per color component for this image.
      Specified by:
        `getBitsPerComponent` in interface `PDFImage`
      Returns:
        the bits per component

    - #### setTransparent

          public void setTransparent(PDFColor t)

      Set the transparent color for this iamge.
      Parameters:
        `t` - the transparent color

    - #### isTransparent

          public boolean isTransparent()

      Check if this image has a transparent color.
      Specified by:
        `isTransparent` in interface `PDFImage`
      Returns:
        true if it has a transparent color

    - #### getTransparentColor

          public PDFColor getTransparentColor()

      Get the transparent color for this image.
      Specified by:
        `getTransparentColor` in interface `PDFImage`
      Returns:
        the transparent color if any

    - #### getMask

          public String getMask()

      Get the bitmap mask reference for this image. Current not supported.
      Specified by:
        `getMask` in interface `PDFImage`
      Returns:
        the bitmap mask reference

    - #### getSoftMaskReference

          public PDFReference getSoftMaskReference()

      Get the PDF reference for a soft mask.
      Specified by:
        `getSoftMaskReference` in interface `PDFImage`
      Returns:
        the PDF reference for a soft mask image (or null if there's no soft mask)

    - #### isInverted

          public boolean isInverted()

      Specified by:
        `isInverted` in interface `PDFImage`
      Returns:
        true for CMYK images generated by Adobe Photoshop

    - #### outputContents

          public void outputContents(OutputStream out)
                              throws IOException

      Writes the raw, unencoded contents of the image to a given output stream.
      Specified by:
        `outputContents` in interface `PDFImage`
      Parameters:
        `out` - OutputStream to write to
      Throws:
        `IOException` - if there creating stream

    - #### populateXObjectDictionary

          public void populateXObjectDictionary(PDFDictionary dict)

      Populates the XObject's dictionary with additional values. The values are added to the dictionary after all the values obtained from other methods from this interface have been put into the dictionary. That allows to override certain values.
      Specified by:
        `populateXObjectDictionary` in interface `PDFImage`
      Parameters:
        `dict` - the dictionary to fill

    - #### getICCStream

          public PDFICCStream getICCStream()

      Get the ICC stream.
      Specified by:
        `getICCStream` in interface `PDFImage`
      Returns:
        always returns null since this has no icc color space

    - #### isPS

          public boolean isPS()

      Check if this is a postscript image.
      Specified by:
        `isPS` in interface `PDFImage`
      Returns:
        always returns false

    - #### getFilterHint

          public String getFilterHint()

      Returns a hint in form of a String (Possible values from PDFFilterList) indicating which filter setup should be used to encode the object.
      Specified by:
        `getFilterHint` in interface `PDFImage`
      Returns:
        the filter setup hint

    - #### getPDFFilter

          public PDFFilter getPDFFilter()

      Get the PDF Filter to be applied to the image.
      Specified by:
        `getPDFFilter` in interface `PDFImage`
      Returns:
        the PDF Filter or null

    - #### setPDFFilter

          public void setPDFFilter(PDFFilter pdfFilter)

    - #### multipleFiltersAllowed

          public boolean multipleFiltersAllowed()

      Indicates whether multiple image filters are allowed; this is implemented because Adobe Reader does not like multiple FlateDecode filters applied to an image even though that allowed by the PDF spec; this is probable due to security concerns since many PDF malware exploits, like zip bombs, make use of a chain of FlateDecode filters.
      Specified by:
        `multipleFiltersAllowed` in interface `PDFImage`

    - #### disallowMultipleFilters

          public void disallowMultipleFilters()

      Disallows multiple filters.

Copyright © 2025 Apache Software Foundation. All rights reserved.