Class Image

All Implemented Interfaces:
IAbstractElement, IElement, ILeafElement, IPropertyContainer, IAccessibleElement

public class Image extends AbstractElement<Image> implements ILeafElement, IAccessibleElement
A layout element that represents an image for inclusion in the document model.
  • Field Details

  • Constructor Details

    • Image

      public Image (PdfImageXObject xObject)
      Creates an Image from an image XObject, the representation of an image in PDF syntax.
      Parameters:
      xObject - an internal PdfImageXObject
    • Image

      public Image (PdfFormXObject xObject)
      Creates an Image from a form XObject, the representation of a form in PDF syntax.
      Parameters:
      xObject - an internal PdfFormXObject
    • Image

      public Image (PdfImageXObject xObject, float width)
      Creates an Image from an image XObject, the representation of an image in PDF syntax, with a custom width.
      Parameters:
      xObject - an internal PdfImageXObject
      width - a float value
    • Image

      public Image (PdfImageXObject xObject, float left, float bottom, float width)
      Creates an Image from an image XObject, the representation of an image in PDF syntax, with a custom width and on a fixed position.
      Parameters:
      xObject - an internal PdfImageXObject
      left - a float value representing the horizontal offset of the lower left corner of the image
      bottom - a float value representing the vertical offset of the lower left corner of the image
      width - a float value
    • Image

      public Image (PdfImageXObject xObject, float left, float bottom)
      Creates an Image from an image XObject, the representation of an image in PDF syntax, on a fixed position.
      Parameters:
      xObject - an internal PdfImageXObject
      left - a float value representing the horizontal offset of the lower left corner of the image
      bottom - a float value representing the vertical offset of the lower left corner of the image
    • Image

      public Image (PdfFormXObject xObject, float left, float bottom)
      Creates an Image from a form XObject, the representation of a form in PDF syntax.
      Parameters:
      xObject - an internal PdfFormXObject
      left - a float value representing the horizontal offset of the lower left corner of the form
      bottom - a float value representing the vertical offset of the lower left corner of the form
    • Image

      public Image (ImageData img)
      Creates an Image from an image resource, read in from a file with the iText I/O module.
      Parameters:
      img - an internal representation of the image resource
    • Image

      public Image (ImageData img, float left, float bottom)
      Creates an Image from an image resource, read in from a file with the iText I/O module, on a fixed position.
      Parameters:
      img - an internal representation of the image resource
      left - a float value representing the horizontal offset of the lower left corner of the image
      bottom - a float value representing the vertical offset of the lower left corner of the image
    • Image

      public Image (ImageData img, float left, float bottom, float width)
      Creates an Image from an image resource, read in from a file with the iText I/O module, with a custom width and on a fixed position.
      Parameters:
      img - an internal representation of the image resource
      left - a float value representing the horizontal offset of the lower left corner of the image
      bottom - a float value representing the vertical offset of the lower left corner of the image
      width - a float value
  • Method Details

    • getXObject

      public PdfXObject getXObject()
      Gets the XObject contained in this image object
      Returns:
      a PdfXObject
    • setRotationAngle

      public Image setRotationAngle (double radAngle)
      Sets the rotation radAngle.
      Parameters:
      radAngle - a value in radians
      Returns:
      this element
    • getMarginLeft

      public UnitValue getMarginLeft()
      Gets the current left margin width of the element.
      Returns:
      the left margin width, as a UnitValue object
    • setMarginLeft

      public Image setMarginLeft (float value)
      Sets the left margin width of the element.
      Parameters:
      value - the new left margin width
      Returns:
      this element
    • getMarginRight

      public UnitValue getMarginRight()
      Gets the current right margin width of the image.
      Returns:
      the right margin width, as a UnitValue object
    • setMarginRight

      public Image setMarginRight (float value)
      Sets the right margin width of the image.
      Parameters:
      value - the new right margin width
      Returns:
      this image
    • getMarginTop

      public UnitValue getMarginTop()
      Gets the current top margin width of the image.
      Returns:
      the top margin width, as a UnitValue object
    • setMarginTop

      public Image setMarginTop (float value)
      Sets the top margin width of the image.
      Parameters:
      value - the new top margin width
      Returns:
      this image
    • getMarginBottom

      public UnitValue getMarginBottom()
      Gets the current bottom margin width of the image.
      Returns:
      the bottom margin width, as a UnitValue object
    • setMarginBottom

      public Image setMarginBottom (float value)
      Sets the bottom margin width of the image.
      Parameters:
      value - the new bottom margin width
      Returns:
      this image
    • setMargins

      public Image setMargins (float marginTop, float marginRight, float marginBottom, float marginLeft)
      Sets the margins around the image to a series of new widths.
      Parameters:
      marginTop - the new margin top width
      marginRight - the new margin right width
      marginBottom - the new margin bottom width
      marginLeft - the new margin left width
      Returns:
      this image
    • getPaddingLeft

      public UnitValue getPaddingLeft()
      Gets the current left padding width of the image.
      Returns:
      the left padding width, as a UnitValue object
    • setPaddingLeft

      public Image setPaddingLeft (float value)
      Sets the left padding width of the image.
      Parameters:
      value - the new left padding width
      Returns:
      this image
    • getPaddingRight

      public UnitValue getPaddingRight()
      Gets the current right padding width of the image.
      Returns:
      the right padding width, as a UnitValue object
    • setPaddingRight

      public Image setPaddingRight (float value)
      Sets the right padding width of the image.
      Parameters:
      value - the new right padding width
      Returns:
      this image
    • getPaddingTop

      public UnitValue getPaddingTop()
      Gets the current top padding width of the image.
      Returns:
      the top padding width, as a UnitValue object
    • setPaddingTop

      public Image setPaddingTop (float value)
      Sets the top padding width of the image.
      Parameters:
      value - the new top padding width
      Returns:
      this image
    • getPaddingBottom

      public UnitValue getPaddingBottom()
      Gets the current bottom padding width of the image.
      Returns:
      the bottom padding width, as a UnitValue object
    • setPaddingBottom

      public Image setPaddingBottom (float value)
      Sets the bottom padding width of the image.
      Parameters:
      value - the new bottom padding width
      Returns:
      this image
    • setPadding

      public Image setPadding (float commonPadding)
      Sets all paddings around the image to the same width.
      Parameters:
      commonPadding - the new padding width
      Returns:
      this image
    • setPaddings

      public Image setPaddings (float paddingTop, float paddingRight, float paddingBottom, float paddingLeft)
      Sets the paddings around the image to a series of new widths.
      Parameters:
      paddingTop - the new padding top width
      paddingRight - the new padding right width
      paddingBottom - the new padding bottom width
      paddingLeft - the new padding left width
      Returns:
      this image
    • scale

      public Image scale (float horizontalScaling, float verticalScaling)
      Scale the image relative to its default size.
      Parameters:
      horizontalScaling - the horizontal scaling coefficient. default value 1 = 100%
      verticalScaling - the vertical scaling coefficient. default value 1 = 100%
      Returns:
      this element
    • scaleToFit

      public Image scaleToFit (float fitWidth, float fitHeight)
      Scale the image to an absolute size. This method will preserve the width-height ratio of the image.
      Parameters:
      fitWidth - the new maximum width of the image
      fitHeight - the new maximum height of the image
      Returns:
      this element
    • scaleAbsolute

      public Image scaleAbsolute (float fitWidth, float fitHeight)
      Scale the image to an absolute size. This method will not preserve the width-height ratio of the image.
      Parameters:
      fitWidth - the new absolute width of the image
      fitHeight - the new absolute height of the image
      Returns:
      this element
    • setAutoScale

      public Image setAutoScale (boolean autoScale)
      Sets the autoscale property for both width and height.
      Parameters:
      autoScale - whether or not to let the image resize automatically
      Returns:
      this image
    • setAutoScaleHeight

      public Image setAutoScaleHeight (boolean autoScale)
      Sets the autoscale property for the height of the image. Is currently bugged and will not work as expected.
      Parameters:
      autoScale - whether or not to let the image height resize automatically
      Returns:
      this image
    • setAutoScaleWidth

      public Image setAutoScaleWidth (boolean autoScale)
      Sets the autoscale property for the width of the image.
      Parameters:
      autoScale - whether or not to let the image width resize automatically
      Returns:
      this image
    • setFixedPosition

      public Image setFixedPosition (float left, float bottom)
      Sets values for a absolute repositioning of the Element. Also has as a side effect that the Element's Property.POSITION is changed to fixed.
      Parameters:
      left - horizontal position on the page
      bottom - vertical position on the page
      Returns:
      this image.
    • setFixedPosition

      public Image setFixedPosition (int pageNumber, float left, float bottom)
      Sets values for a absolute repositioning of the Element, on a specific page. Also has as a side effect that the Element's Property.POSITION is changed to fixed.
      Parameters:
      pageNumber - the page where the element must be positioned
      left - horizontal position on the page
      bottom - vertical position on the page
      Returns:
      this Element.
    • getImageWidth

      public float getImageWidth()
      Gets width of the image. It returns width of image or form XObject, not the width set by one of the #setWidth methods
      Returns:
      the original width of the image
    • getImageHeight

      public float getImageHeight()
      Gets height of the image. It returns height of image or form XObject, not the height set by one of the #setHeight methods
      Returns:
      the original height of the image
    • setHeight

      public Image setHeight (float height)
      Sets the height property of the image, measured in points.
      Parameters:
      height - a value measured in points.
      Returns:
      this image.
    • setHeight

      public Image setHeight (UnitValue height)
      Sets the height property of the image with a UnitValue.
      Parameters:
      height - a value measured in points.
      Returns:
      this image.
    • setMaxHeight

      public Image setMaxHeight (float maxHeight)
      Sets the max-height property of the image, measured in points.
      Parameters:
      maxHeight - a value measured in points.
      Returns:
      this image.
    • setMaxHeight

      public Image setMaxHeight (UnitValue maxHeight)
      Sets the max-height property of the image with a UnitValue.
      Parameters:
      maxHeight - a value measured in points.
      Returns:
      this image.
    • setMinHeight

      public Image setMinHeight (float minHeight)
      Sets the min-height property of the image, measured in points.
      Parameters:
      minHeight - a value measured in points.
      Returns:
      this image.
    • setMinHeight

      public Image setMinHeight (UnitValue minHeight)
      Sets the min-height property of the image with a UnitValue.
      Parameters:
      minHeight - a value measured in points.
      Returns:
      this image.
    • setMaxWidth

      public Image setMaxWidth (float maxWidth)
      Sets the max-width property of the image, measured in points.
      Parameters:
      maxWidth - a value measured in points.
      Returns:
      this image.
    • setMaxWidth

      public Image setMaxWidth (UnitValue maxWidth)
      Sets the max-width property of the image with a UnitValue.
      Parameters:
      maxWidth - a value measured in points.
      Returns:
      this image.
    • setMinWidth

      public Image setMinWidth (float minWidth)
      Sets the min-width property of the image, measured in points.
      Parameters:
      minWidth - a value measured in points.
      Returns:
      this image.
    • setMinWidth

      public Image setMinWidth (UnitValue minWidth)
      Sets the min-width property of the image with a UnitValue.
      Parameters:
      minWidth - a value measured in points.
      Returns:
      this image.
    • setWidth

      public Image setWidth (float width)
      Sets the width property of the image, measured in points.
      Parameters:
      width - a value measured in points.
      Returns:
      this image.
    • setWidth

      public Image setWidth (UnitValue width)
      Sets the width property of the image with a UnitValue.
      Parameters:
      width - a UnitValue object
      Returns:
      this image.
    • getWidth

      public UnitValue getWidth()
      Gets the width property of the image.
      Returns:
      the width of the element, with a value and a measurement unit.
      See Also:
    • getImageScaledWidth

      public float getImageScaledWidth()
      Gets scaled width of the image.
      Returns:
      the current scaled width
    • getImageScaledHeight

      public float getImageScaledHeight()
      Gets scaled height of the image.
      Returns:
      the current scaled height
    • setObjectFit

      public Image setObjectFit (ObjectFit objectFit)
      Sets an object-fit mode for the image.
      Parameters:
      objectFit - is the ObjectFit mode
      Returns:
      this image
    • getObjectFit

      public ObjectFit getObjectFit()
      Retrieves the ObjectFit mode for the image.
      Returns:
      an object-fit mode for the image if it was set and default value ObjectFit.FILL otherwise
    • getAccessibilityProperties

      public AccessibilityProperties getAccessibilityProperties()
      Description copied from interface: IAccessibleElement
      Specified by:
      getAccessibilityProperties in interface IAccessibleElement
      Returns:
      an interface that allows to specify properties of a tagged element in Tagged PDF.
    • setNeutralRole

      public Image setNeutralRole()
      Give this element a neutral role. See also AccessibilityProperties.setRole(String).
      Returns:
      this Element
    • makeNewRenderer

      protected IRenderer makeNewRenderer()
      Description copied from class: AbstractElement
      Creates new renderer instance.
      Specified by:
      makeNewRenderer in class AbstractElement<Image>
      Returns:
      new IRenderer