Class Image

All Implemented Interfaces:
Element
Direct Known Subclasses:
ImgCCITT, ImgJBIG2, ImgRaw, ImgTemplate, ImgWMF, Jpeg, Jpeg2000

public abstract class Image extends Rectangle
An Image is the representation of a graphic element (JPEG, PNG or GIF) that has to be inserted into the document Security consideration: This method accepts input and processes it without built-in validation, filtering, or access restrictions. It may load resources such as local files or external URLs, depending on the input. This can introduce security risks including unauthorized file access, directory traversal, or server-side request forgery (SSRF). It is the responsibility of the calling application to validate and sanitize all input before passing it to this method, especially when handling user-controlled or external data. Refer to established secure coding guidelines to ensure safe usage.
See Also:
  • Field Details

    • imageDataPattern

      private static final Pattern imageDataPattern
      used to detect image base64 data pattern
    • DEFAULT

      public static final int DEFAULT
      Image alignment: Default alignment (same as LEFT). The image will be placed on the left side of the page.
      See Also:
    • LEFT

      public static final int LEFT
      Image alignment: Left-align the image. The image will be placed on the left side of the page. Can be combined with TEXTWRAP or UNDERLYING using bitwise OR. Example: image.setAlignment(Image.LEFT | Image.TEXTWRAP);
      See Also:
    • MIDDLE

      public static final int MIDDLE
      Image alignment: Center the image horizontally on the page. The image will be placed in the middle of the page width.
      See Also:
    • TEXTWRAP

      public static final int TEXTWRAP
      Image alignment modifier: Allow text to wrap around the image. When combined with LEFT or RIGHT, text will flow around the image on the opposite side. This is useful for creating inline images where text continues alongside the image instead of the image occupying its own line.

      Example for an image with text wrapping on the right: image.setAlignment(Image.LEFT | Image.TEXTWRAP);

      Example for an image with text wrapping on the left: image.setAlignment(Image.RIGHT | Image.TEXTWRAP);

      See Also:
    • UNDERLYING

      public static final int UNDERLYING
      Image alignment modifier: Place the image behind (underneath) the text. When combined with other alignment flags, the image will be rendered as a background element with text overlaying it. This is useful for watermarks, seals, or stamps that should appear behind text content.

      Example for a background image on the left: image.setAlignment(Image.LEFT | Image.UNDERLYING);

      Example for a seal that appears behind text: image.setAlignment(Image.RIGHT | Image.UNDERLYING);

      See Also:
    • AX

      public static final int AX
      This represents a coordinate in the transformation matrix.
      See Also:
    • AY

      public static final int AY
      This represents a coordinate in the transformation matrix.
      See Also:
    • BX

      public static final int BX
      This represents a coordinate in the transformation matrix.
      See Also:
    • BY

      public static final int BY
      This represents a coordinate in the transformation matrix.
      See Also:
    • CX

      public static final int CX
      This represents a coordinate in the transformation matrix.
      See Also:
    • CY

      public static final int CY
      This represents a coordinate in the transformation matrix.
      See Also:
    • DX

      public static final int DX
      This represents a coordinate in the transformation matrix.
      See Also:
    • DY

      public static final int DY
      This represents a coordinate in the transformation matrix.
      See Also:
    • ORIGINAL_NONE

      public static final int ORIGINAL_NONE
      type of image
      See Also:
    • ORIGINAL_JPEG

      public static final int ORIGINAL_JPEG
      type of image
      See Also:
    • ORIGINAL_PNG

      public static final int ORIGINAL_PNG
      type of image
      See Also:
    • ORIGINAL_GIF

      public static final int ORIGINAL_GIF
      type of image
      See Also:
    • ORIGINAL_BMP

      public static final int ORIGINAL_BMP
      type of image
      See Also:
    • ORIGINAL_TIFF

      public static final int ORIGINAL_TIFF
      type of image
      See Also:
    • ORIGINAL_WMF

      public static final int ORIGINAL_WMF
      type of image
      See Also:
    • ORIGINAL_PS

      public static final int ORIGINAL_PS
      type of image
      See Also:
    • ORIGINAL_JPEG2000

      public static final int ORIGINAL_JPEG2000
      type of image
      See Also:
    • ORIGINAL_JBIG2

      public static final int ORIGINAL_JBIG2
      type of image
      Since:
      2.1.5
      See Also:
    • PNGID

      public static final int[] PNGID
    • serialId

      static long serialId
      a static that is used for attributing a unique id to each image.
    • type

      protected int type
      The image type.
    • url

      protected URL url
      The URL of the image.
    • rawData

      protected byte[] rawData
      The raw data of the image.
    • bpc

      protected int bpc
      The bits per component of the raw image. It also flags a CCITT image.
    • template

      protected PdfTemplate[] template
      The template to be treated as an image.
    • alignment

      protected int alignment
      The alignment of the Image.
    • alt

      protected String alt
      Text that can be shown instead of the image.
    • absoluteX

      protected float absoluteX
      This is the absolute X-position of the image.
    • absoluteY

      protected float absoluteY
      This is the absolute Y-position of the image.
    • plainWidth

      protected float plainWidth
      This is the width of the image without rotation.
    • plainHeight

      protected float plainHeight
      This is the width of the image without rotation.
    • scaledWidth

      protected float scaledWidth
      This is the scaled width of the image taking rotation into account.
    • scaledHeight

      protected float scaledHeight
      This is the original height of the image taking rotation into account.
    • compressionLevel

      protected int compressionLevel
      The compression level of the content streams.
      Since:
      2.1.3
    • mySerialId

      protected Long mySerialId
      an iText attributed unique id for this image.
    • rotationRadians

      protected float rotationRadians
      This is the rotation of the image in radians.
    • indentationLeft

      protected float indentationLeft
      the indentation to the left.
    • indentationRight

      protected float indentationRight
      the indentation to the right.
    • spacingBefore

      protected float spacingBefore
      The spacing before the image.
    • spacingAfter

      protected float spacingAfter
      The spacing after the image.
    • annotation

      protected Annotation annotation
      if the annotation is not null the image will be clickable.
    • layer

      protected PdfOCG layer
      Optional Content layer to which we want this Image to belong.
    • interpolation

      protected boolean interpolation
      Holds value of property interpolation.
    • originalType

      protected int originalType
      Holds value of property originalType.
    • originalData

      protected byte[] originalData
      Holds value of property originalData.
    • deflated

      protected boolean deflated
      Holds value of property deflated.
    • dpiX

      protected int dpiX
      Holds value of property dpiX.
    • dpiY

      protected int dpiY
      Holds value of property dpiY.
    • colorspace

      protected int colorspace
      this is the colorspace of a jpeg-image.
    • invert

      protected boolean invert
      Image color inversion
    • profile

      protected ICC_Profile profile
      ICC Profile attached
    • mask

      protected boolean mask
      Is this image a mask?
    • imageMask

      protected Image imageMask
      The image that serves as a mask for this image.
    • transparency

      protected int[] transparency
      this is the transparency information of the raw image
    • directReference

      private PdfIndirectReference directReference
      Holds value of property directReference. An image is embedded into a PDF as an Image XObject. This object is referenced by a PdfIndirectReference object.
    • initialRotation

      private float initialRotation
      Holds value of property initialRotation.
    • widthPercentage

      private float widthPercentage
      Holds value of property widthPercentage.
    • XYRatio

      private float XYRatio
      Holds value of property XYRatio.
    • additional

      private PdfDictionary additional
      a dictionary with additional information
    • smask

      private boolean smask
      Holds value of property smask.
  • Constructor Details

    • Image

      public Image(URL url)
      Constructs an Image -object, using an url .
      Parameters:
      url - the URL where the image can be found.
    • Image

      protected Image(Image image)
      Constructs an Image -object, using an url .
      Parameters:
      image - another Image object.
  • Method Details

    • getInstance

      public static Image getInstance(String mediaType, String base64Data) throws BadElementException
      Throws:
      BadElementException
    • getInstance

      public static Image getInstance(URL url) throws BadElementException, IOException
      Gets an instance of an Image. Security consideration: This method accepts input and processes it without built-in validation, filtering, or access restrictions. It may load resources such as local files or external URLs, depending on the input. This can introduce security risks including unauthorized file access, directory traversal, or server-side request forgery (SSRF). It is the responsibility of the calling application to validate and sanitize all input before passing it to this method, especially when handling user-controlled or external data. Refer to established secure coding guidelines to ensure safe usage.
      Parameters:
      url - an URL
      Returns:
      an Image
      Throws:
      BadElementException - if error in creating ImgWMF
      MalformedURLException - if bad url
      IOException - if image is not recognized
    • getInstance

      public static Image getInstance(String filename) throws BadElementException, IOException
      Gets an instance of an Image. Security consideration: This method accepts input and processes it without built-in validation, filtering, or access restrictions. It may load resources such as local files or external URLs, depending on the input. This can introduce security risks including unauthorized file access, directory traversal, or server-side request forgery (SSRF). It is the responsibility of the calling application to validate and sanitize all input before passing it to this method, especially when handling user-controlled or external data. Refer to established secure coding guidelines to ensure safe usage.
      Parameters:
      filename - a filename
      Returns:
      an object of type Gif,Jpeg or Png
      Throws:
      BadElementException - if error in creating ImgWMF
      IOException - if image is not recognized
    • getInstanceFromClasspath

      public static Image getInstanceFromClasspath(String filename) throws BadElementException, IOException
      Gets an instance of an Image from the classpath. Security consideration: This method accepts input and processes it without built-in validation, filtering, or access restrictions. It may load resources such as local files or external URLs, depending on the input. This can introduce security risks including unauthorized file access, directory traversal, or server-side request forgery (SSRF). It is the responsibility of the calling application to validate and sanitize all input before passing it to this method, especially when handling user-controlled or external data. Refer to established secure coding guidelines to ensure safe usage.
      Parameters:
      filename - a filename
      Returns:
      an object of type Gif,Jpeg or Png
      Throws:
      BadElementException - if error in creating ImgWMF
      IOException - if image is not recognized
    • getInstance

      public static Image getInstance(byte[] imgb) throws BadElementException, IOException
      gets an instance of an Image
      Parameters:
      imgb - raw image date
      Returns:
      an Image object
      Throws:
      BadElementException - if error in creating ImgWMF
      IOException - if image is not recognized
    • readFirst8Chars

      private static int[] readFirst8Chars(InputStream is) throws IOException
      Reads the first 8 bytes of an InputStream and returns them as an int array. Security consideration: This method accepts input and processes it without built-in validation, filtering, or access restrictions. It may load resources such as local files or external URLs, depending on the input. This can introduce security risks including unauthorized file access, directory traversal, or server-side request forgery (SSRF). It is the responsibility of the calling application to validate and sanitize all input before passing it to this method, especially when handling user-controlled or external data. Refer to established secure coding guidelines to ensure safe usage.
      Parameters:
      is -
      Returns:
      Throws:
      IOException
    • getInstance

      public static Image getInstance(int width, int height, int components, int bpc, byte[] data) throws BadElementException
      Gets an instance of an Image in raw mode.
      Parameters:
      width - the width of the image in pixels
      height - the height of the image in pixels
      components - 1,3 or 4 for GrayScale, RGB and CMYK
      bpc - bits per component
      data - the image data
      Returns:
      an object of type ImgRaw
      Throws:
      BadElementException - on error
    • getInstance

      public static Image getInstance(int width, int height, byte[] data, byte[] globals)
      Creates a JBIG2 Image.
      Parameters:
      width - the width of the image
      height - the height of the image
      data - the raw image data
      globals - JBIG2 globals
      Returns:
      an Image Object
      Since:
      2.1.5
    • getInstance

      public static Image getInstance(int width, int height, boolean reverseBits, int typeCCITT, int parameters, byte[] data) throws BadElementException
      Creates an Image with CCITT G3 or G4 compression. It assumes that the data bytes are already compressed.
      Parameters:
      width - the exact width of the image
      height - the exact height of the image
      reverseBits - reverses the bits in data. Bit 0 is swapped with bit 7 and so on
      typeCCITT - the type of compression in data. It can be CCITTG4, CCITTG31D, CCITTG32D
      parameters - parameters associated with this stream. Possible values are CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFLINE and CCITT_ENDOFBLOCK or a combination of them
      data - the image data
      Returns:
      an Image object
      Throws:
      BadElementException - on error
    • getInstance

      public static Image getInstance(int width, int height, boolean reverseBits, int typeCCITT, int parameters, byte[] data, int[] transparency) throws BadElementException
      Creates an Image with CCITT G3 or G4 compression. It assumes that the data bytes are already compressed.
      Parameters:
      width - the exact width of the image
      height - the exact height of the image
      reverseBits - reverses the bits in data. Bit 0 is swapped with bit 7 and so on
      typeCCITT - the type of compression in data. It can be CCITTG4, CCITTG31D, CCITTG32D
      parameters - parameters associated with this stream. Possible values are CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFLINE and CCITT_ENDOFBLOCK or a combination of them
      data - the image data
      transparency - transparency information in the Mask format of the image dictionary
      Returns:
      an Image object
      Throws:
      BadElementException - on error
    • getInstance

      public static Image getInstance(int width, int height, int components, int bpc, byte[] data, int[] transparency) throws BadElementException
      Gets an instance of an Image in raw mode.
      Parameters:
      width - the width of the image in pixels
      height - the height of the image in pixels
      components - 1,3 or 4 for GrayScale, RGB and CMYK
      bpc - bits per component
      data - the image data
      transparency - transparency information in the Mask format of the image dictionary
      Returns:
      an object of type ImgRaw
      Throws:
      BadElementException - on error
    • getInstance

      public static Image getInstance(PdfTemplate template) throws BadElementException
      gets an instance of an Image
      Parameters:
      template - a PdfTemplate that has to be wrapped in an Image object
      Returns:
      an Image object
      Throws:
      BadElementException - on error
    • getInstance

      public static Image getInstance(Image image, Color color, boolean forceBW) throws BadElementException, IOException
      Gets an instance of an Image from a java.awt.Image.
      Parameters:
      image - the java.awt.Image to convert
      color - if different from null the transparency pixels are replaced by this color
      forceBW - if true the image is treated as black and white
      Returns:
      an object of type ImgRaw
      Throws:
      BadElementException - on error
      IOException - on error
    • generateIndexedColorPixelData

      private static byte[] generateIndexedColorPixelData(int width, int bitsPerPixel, int height, WritableRaster raster)
      Generates PDF-compliant pixel data for indexed color images (IndexColorModel).

      This method packs palette indices from a WritableRaster into a byte array that strictly adheres to PDF specification requirements for indexed color image storage:

      • Pixel indices are packed starting from the Most Significant Bit (MSB, bit 7) of each byte (PDF mandatory rule)
      • Each row of pixel data is byte-aligned (padded with zeros to match calculated row stride)
      • Supports standard indexed color bit depths: 1, 2, 4, 8 bits per pixel
      • Normalizes palette indices to unsigned 0-255 range to prevent invalid negative values
      Parameters:
      width - Width of the indexed color image (in pixels)
      bitsPerPixel - Number of bits per pixel (must be 1, 2, 4, or 8 for valid indexed color)
      height - Height of the indexed color image (in pixels)
      raster - WritableRaster containing the indexed color pixel indices (from IndexColorModel BufferedImage)
      Returns:
      Byte array of pixel data packed according to PDF indexed color specifications, with row-wise byte alignment
      See Also:
    • packPixelByBitDepth

      private static int packPixelByBitDepth(int bitsPerPixel, int pixelIndex, byte[] pixelData, int bytePos, int bitOffset)
      Packs a single pixel index into the target byte array based on specified bit depth (PDF MSB-first rule).
    • getInstance

      public static Image getInstance(Image image, Color color) throws BadElementException, IOException
      Gets an instance of an Image from a java.awt.Image.
      Parameters:
      image - the java.awt.Image to convert
      color - if different from null the transparency pixels are replaced by this color
      Returns:
      an object of type ImgRaw
      Throws:
      BadElementException - on error
      IOException - on error
    • getInstance

      public static Image getInstance(PdfWriter writer, Image awtImage, float quality) throws BadElementException, IOException
      Gets an instance of a Image from a java.awt.Image. The image is added as a JPEG with a user defined quality.
      Parameters:
      writer - the PdfWriter object to which the image will be added
      awtImage - the java.awt.Image to convert
      quality - a float value between 0 and 1
      Returns:
      an object of type PdfTemplate
      Throws:
      BadElementException - on error
      IOException - on error
    • getInstance

      public static Image getInstance(PdfContentByte cb, Image awtImage, float quality) throws BadElementException, IOException
      Gets an instance of a Image from a java.awt.Image. The image is added as a JPEG with a user defined quality.
      Parameters:
      cb - the PdfContentByte object to which the image will be added
      awtImage - the java.awt.Image to convert
      quality - a float value between 0 and 1
      Returns:
      an object of type PdfTemplate
      Throws:
      BadElementException - on error
      IOException - on error
    • getInstance

      public static Image getInstance(PRIndirectReference ref) throws BadElementException
      Reuses an existing image.
      Parameters:
      ref - the reference to the image dictionary
      Returns:
      the image
      Throws:
      BadElementException - on error
    • getInstance

      public static Image getInstance(Image image)
      gets an instance of an Image
      Parameters:
      image - an Image object
      Returns:
      a new Image object
    • getSerialId

      protected static Long getSerialId()
      Creates a new serial id.
      Returns:
      a new serial id
    • getDirectReference

      public PdfIndirectReference getDirectReference()
      Getter for property directReference.
      Returns:
      Value of property directReference.
    • setDirectReference

      public void setDirectReference(PdfIndirectReference directReference)
      Setter for property directReference.
      Parameters:
      directReference - New value of property directReference.
    • type

      public int type()
      Returns the type.
      Specified by:
      type in interface Element
      Overrides:
      type in class Rectangle
      Returns:
      a type
    • isNestable

      public boolean isNestable()
      Description copied from interface: Element
      Checks if this element is nestable.
      Specified by:
      isNestable in interface Element
      Overrides:
      isNestable in class Rectangle
      Returns:
      true if this element can be nested inside other elements.
      Since:
      iText 2.0.8
      See Also:
    • isJpeg

      public boolean isJpeg()
      Returns true if the image is a Jpeg -object.
      Returns:
      a boolean
    • isImgRaw

      public boolean isImgRaw()
      Returns true if the image is a ImgRaw -object.
      Returns:
      a boolean
    • isImgTemplate

      public boolean isImgTemplate()
      Returns true if the image is an ImgTemplate -object.
      Returns:
      a boolean
    • getUrl

      public URL getUrl()
      Gets the String -representation of the reference to the image.
      Returns:
      a String
    • setUrl

      public void setUrl(URL url)
      Sets the url of the image
      Parameters:
      url - the url of the image
    • getRawData

      public byte[] getRawData()
      Gets the raw data for the image.

      Remark: this only makes sense for Images of the type RawImage .

      Returns:
      the raw data
    • getBpc

      public int getBpc()
      Gets the bpc for the image.

      Remark: this only makes sense for Images of the type RawImage .

      Returns:
      a bpc value
    • getTemplateData

      public PdfTemplate getTemplateData()
      Gets the template to be used as an image.

      Remark: this only makes sense for Images of the type ImgTemplate .

      Returns:
      the template
    • setTemplateData

      public void setTemplateData(PdfTemplate template)
      Sets data from a PdfTemplate
      Parameters:
      template - the template with the content
    • getAlignment

      public int getAlignment()
      Gets the alignment for the image.

      The returned value may be a combination of alignment flags combined using bitwise OR. Use bitwise AND (&) to check for specific flags:

      int alignment = image.getAlignment();
      boolean hasTextwrap = (alignment & Image.TEXTWRAP) != 0;
      boolean isUnderlying = (alignment & Image.UNDERLYING) != 0;
      
      Returns:
      the alignment value (possibly a combination of flags)
      See Also:
    • setAlignment

      public void setAlignment(int alignment)
      Sets the alignment for the image.

      The alignment parameter can be one of the following base values:

      • LEFT or DEFAULT - Align the image to the left
      • RIGHT - Align the image to the right
      • MIDDLE - Center the image horizontally

      The base alignment can be combined with modifiers using bitwise OR (|):

      • TEXTWRAP - Allow text to wrap around the image (useful for inline images)
      • UNDERLYING - Place the image behind text (useful for watermarks, seals, stamps)

      Examples:

      // Image aligned left with text wrapping around it on the right
      image.setAlignment(Image.LEFT | Image.TEXTWRAP);
      
      // Image aligned right with text wrapping around it on the left
      image.setAlignment(Image.RIGHT | Image.TEXTWRAP);
      
      // Seal or stamp that appears behind text on the right
      image.setAlignment(Image.RIGHT | Image.UNDERLYING);
      
      // Watermark that appears behind centered text
      image.setAlignment(Image.MIDDLE | Image.UNDERLYING);
      
      Parameters:
      alignment - the alignment value (can be a combination of flags using bitwise OR)
    • getAlt

      public String getAlt()
      Gets the alternative text for the image.
      Returns:
      a String
    • setAlt

      public void setAlt(String alt)
      Sets the alternative information for the image.
      Parameters:
      alt - the alternative information
    • setAbsolutePosition

      public void setAbsolutePosition(float absoluteX, float absoluteY)
      Sets the absolute position of the Image.
      Parameters:
      absoluteX - absolute x position
      absoluteY - absolute y position
    • hasAbsoluteX

      public boolean hasAbsoluteX()
      Checks if the Images has to be added at an absolute X position.
      Returns:
      a boolean
    • getAbsoluteX

      public float getAbsoluteX()
      Returns the absolute X position.
      Returns:
      a position
    • hasAbsoluteY

      public boolean hasAbsoluteY()
      Checks if the Images has to be added at an absolute position.
      Returns:
      a boolean
    • getAbsoluteY

      public float getAbsoluteY()
      Returns the absolute Y position.
      Returns:
      a position
    • getScaledWidth

      public float getScaledWidth()
      Gets the scaled width of the image.
      Returns:
      a value
    • getScaledHeight

      public float getScaledHeight()
      Gets the scaled height of the image.
      Returns:
      a value
    • getPlainWidth

      public float getPlainWidth()
      Gets the plain width of the image.
      Returns:
      a value
    • getPlainHeight

      public float getPlainHeight()
      Gets the plain height of the image.
      Returns:
      a value
    • scaleAbsolute

      public void scaleAbsolute(float newWidth, float newHeight)
      Scale the image to an absolute width and an absolute height.
      Parameters:
      newWidth - the new width
      newHeight - the new height
    • scaleAbsoluteWidth

      public void scaleAbsoluteWidth(float newWidth)
      Scale the image to an absolute width.
      Parameters:
      newWidth - the new width
    • scaleAbsoluteHeight

      public void scaleAbsoluteHeight(float newHeight)
      Scale the image to an absolute height.
      Parameters:
      newHeight - the new height
    • scalePercent

      public void scalePercent(float percent)
      Scale the image to a certain percentage.
      Parameters:
      percent - the scaling percentage
    • scalePercent

      public void scalePercent(float percentX, float percentY)
      Scale the width and height of an image to a certain percentage.
      Parameters:
      percentX - the scaling percentage of the width
      percentY - the scaling percentage of the height
    • scaleToFit

      public void scaleToFit(float fitWidth, float fitHeight)
      Scales the image so that it fits a certain width and height.
      Parameters:
      fitWidth - the width to fit
      fitHeight - the height to fit
    • matrix

      public float[] matrix()
      Returns the transformation matrix of the image.
      Returns:
      an array [AX, AY, BX, BY, CX, CY, DX, DY]
    • getMySerialId

      public Long getMySerialId()
      Returns a serial id for the Image (reuse the same image more than once)
      Returns:
      a serialId
    • getImageRotation

      public float getImageRotation()
      Gets the current image rotation in radians.
      Returns:
      the current image rotation in radians
    • setRotation

      public void setRotation(float r)
      Sets the rotation of the image in radians.
      Parameters:
      r - rotation in radians
    • setRotationDegrees

      public void setRotationDegrees(float deg)
      Sets the rotation of the image in degrees.
      Parameters:
      deg - rotation in degrees
    • getInitialRotation

      public float getInitialRotation()
      Getter for property initialRotation.
      Returns:
      Value of property initialRotation.
    • setInitialRotation

      public void setInitialRotation(float initialRotation)
      Some image formats, like TIFF may present the images rotated that have to be compensated.
      Parameters:
      initialRotation - New value of property initialRotation.
    • getIndentationLeft

      public float getIndentationLeft()
      Gets the left indentation.
      Returns:
      the left indentation
    • setIndentationLeft

      public void setIndentationLeft(float f)
      Sets the left indentation.
      Parameters:
      f - left indentation
    • getIndentationRight

      public float getIndentationRight()
      Gets the right indentation.
      Returns:
      the right indentation
    • setIndentationRight

      public void setIndentationRight(float f)
      Sets the right indentation.
      Parameters:
      f - right indentation
    • getSpacingBefore

      public float getSpacingBefore()
      Gets the spacing before this image.
      Returns:
      the spacing
    • setSpacingBefore

      public void setSpacingBefore(float spacing)
      Sets the spacing before this image.
      Parameters:
      spacing - the new spacing
    • getSpacingAfter

      public float getSpacingAfter()
      Gets the spacing before this image.
      Returns:
      the spacing
    • setSpacingAfter

      public void setSpacingAfter(float spacing)
      Sets the spacing after this image.
      Parameters:
      spacing - the new spacing
    • getWidthPercentage

      public float getWidthPercentage()
      Getter for property widthPercentage.
      Returns:
      Value of property widthPercentage.
    • setWidthPercentage

      public void setWidthPercentage(float widthPercentage)
      Setter for property widthPercentage.
      Parameters:
      widthPercentage - New value of property widthPercentage.
    • getAnnotation

      public Annotation getAnnotation()
      Gets the annotation.
      Returns:
      the annotation that is linked to this image
    • setAnnotation

      public void setAnnotation(Annotation annotation)
      Sets the annotation of this Image.
      Parameters:
      annotation - the annotation
    • getLayer

      public PdfOCG getLayer()
      Gets the layer this image belongs to.
      Returns:
      the layer this image belongs to or null for no layer defined
    • setLayer

      public void setLayer(PdfOCG layer)
      Sets the layer this image belongs to.
      Parameters:
      layer - the layer this image belongs to
    • isInterpolation

      public boolean isInterpolation()
      Getter for property interpolation.
      Returns:
      Value of property interpolation.
    • setInterpolation

      public void setInterpolation(boolean interpolation)
      Sets the image interpolation. Image interpolation attempts to produce a smooth transition between adjacent sample values.
      Parameters:
      interpolation - New value of property interpolation.
    • getOriginalType

      public int getOriginalType()
      Getter for property originalType.
      Returns:
      Value of property originalType.
    • setOriginalType

      public void setOriginalType(int originalType)
      Setter for property originalType.
      Parameters:
      originalType - New value of property originalType.
    • getOriginalData

      public byte[] getOriginalData()
      Getter for property originalData.
      Returns:
      Value of property originalData.
    • setOriginalData

      public void setOriginalData(byte[] originalData)
      Setter for property originalData.
      Parameters:
      originalData - New value of property originalData.
    • isDeflated

      public boolean isDeflated()
      Getter for property deflated.
      Returns:
      Value of property deflated.
    • setDeflated

      public void setDeflated(boolean deflated)
      Setter for property deflated.
      Parameters:
      deflated - New value of property deflated.
    • getDpiX

      public int getDpiX()
      Gets the dots-per-inch in the X direction. Returns 0 if not available.
      Returns:
      the dots-per-inch in the X direction
    • getDpiY

      public int getDpiY()
      Gets the dots-per-inch in the Y direction. Returns 0 if not available.
      Returns:
      the dots-per-inch in the Y direction
    • setDpi

      public void setDpi(int dpiX, int dpiY)
      Sets the dots per inch value
      Parameters:
      dpiX - dpi for x coordinates
      dpiY - dpi for y coordinates
    • getXYRatio

      public float getXYRatio()
      Gets the X/Y pixel dimensionless aspect ratio.
      Returns:
      the X/Y pixel dimensionless aspect ratio
    • setXYRatio

      public void setXYRatio(float XYRatio)
      Sets the X/Y pixel dimensionless aspect ratio.
      Parameters:
      XYRatio - the X/Y pixel dimensionless aspect ratio
    • getColorspace

      public int getColorspace()
      Gets the colorspace for the image.

      Remark: this only makes sense for Images of the type Jpeg.

      Returns:
      a colorspace value
    • isInverted

      public boolean isInverted()
      Getter for the inverted value
      Returns:
      true if the image is inverted
    • setInverted

      public void setInverted(boolean invert)
      Sets inverted true or false
      Parameters:
      invert - true or false
    • tagICC

      public void tagICC(ICC_Profile profile)
      Tags this image with an ICC profile.
      Parameters:
      profile - the profile
    • hasICCProfile

      public boolean hasICCProfile()
      Checks is the image has an ICC profile.
      Returns:
      the ICC profile or null
    • getICCProfile

      public ICC_Profile getICCProfile()
      Gets the images ICC profile.
      Returns:
      the ICC profile
    • getAdditional

      public PdfDictionary getAdditional()
      Getter for the dictionary with additional information.
      Returns:
      a PdfDictionary with additional information.
    • setAdditional

      public void setAdditional(PdfDictionary additional)
      Sets the /Colorspace key.
      Parameters:
      additional - a PdfDictionary with additional information.
    • simplifyColorspace

      public void simplifyColorspace()
      Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray.
    • simplifyColorspace

      private PdfObject simplifyColorspace(PdfArray obj)
      Gets a PDF Name from an array or returns the object that was passed.
    • isMask

      public boolean isMask()
      Returns true if this Image is a mask.
      Returns:
      true if this Image is a mask
    • makeMask

      public void makeMask() throws DocumentException
      Make this Image a mask.
      Throws:
      DocumentException - if this Image can not be a mask
    • isMaskCandidate

      public boolean isMaskCandidate()
      Returns true if this Image has the requisites to be a mask.
      Returns:
      true if this Image can be a mask
    • getImageMask

      public Image getImageMask()
      Gets the explicit masking.
      Returns:
      the explicit masking
    • setImageMask

      public void setImageMask(Image mask) throws DocumentException
      Sets the explicit masking.
      Parameters:
      mask - the mask to be applied
      Throws:
      DocumentException - on error
    • isSmask

      public boolean isSmask()
      Getter for property smask.
      Returns:
      Value of property smask.
    • setSmask

      public void setSmask(boolean smask)
      Setter for property smask.
      Parameters:
      smask - New value of property smask.
    • getTransparency

      public int[] getTransparency()
      Returns the transparency.
      Returns:
      the transparency values
    • setTransparency

      public void setTransparency(int[] transparency)
      Sets the transparency values
      Parameters:
      transparency - the transparency values
    • getCompressionLevel

      public int getCompressionLevel()
      Returns the compression level used for images written as a compressed stream.
      Returns:
      the compression level (0 = best speed, 9 = best compression, -1 is default)
      Since:
      2.1.3
    • setCompressionLevel

      public void setCompressionLevel(int compressionLevel)
      Sets the compression level to be used if the image is written as a compressed stream.
      Parameters:
      compressionLevel - a value between 0 (best speed) and 9 (best compression)
      Since:
      2.1.3
    • isJBIG2

      private static boolean isJBIG2(int[] array)
    • isGif

      private static boolean isGif(int[] array)
    • isPng

      private static boolean isPng(int[] array)
    • isBmp

      private static boolean isBmp(int[] array)
    • isJpeg

      private static boolean isJpeg(int[] array)
    • isJpeg2000

      private static boolean isJpeg2000(int[] array)
    • isTiff

      private static boolean isTiff(int[] array)
    • isWMF

      private static boolean isWMF(int[] array)