Package com.itextpdf.layout.element
Class Image
- java.lang.Object
-
- com.itextpdf.commons.actions.sequence.AbstractIdentifiableElement
-
- com.itextpdf.layout.ElementPropertyContainer<T>
-
- com.itextpdf.layout.element.AbstractElement<Image>
-
- com.itextpdf.layout.element.Image
-
- All Implemented Interfaces:
IAbstractElement
,IElement
,ILeafElement
,IPropertyContainer
,IAccessibleElement
- Direct Known Subclasses:
SvgImage
public class Image extends AbstractElement<Image> implements ILeafElement, IAccessibleElement
A layout element that represents an image for inclusion in the document model.
-
-
Field Summary
Fields Modifier and Type Field Description protected DefaultAccessibilityProperties
tagProperties
protected PdfXObject
xObject
-
Fields inherited from class com.itextpdf.layout.element.AbstractElement
childElements, nextRenderer, styles
-
Fields inherited from class com.itextpdf.layout.ElementPropertyContainer
properties
-
-
Constructor Summary
Constructors Constructor Description Image(ImageData img)
Creates anImage
from an image resource, read in from a file with the iText I/O module.Image(ImageData img, float left, float bottom)
Creates anImage
from an image resource, read in from a file with the iText I/O module, on a fixed position.Image(ImageData img, float left, float bottom, float width)
Creates anImage
from an image resource, read in from a file with the iText I/O module, with a custom width and on a fixed position.Image(PdfFormXObject xObject)
Creates anImage
from a form XObject, the representation of a form in PDF syntax.Image(PdfFormXObject xObject, float left, float bottom)
Creates anImage
from a form XObject, the representation of a form in PDF syntax.Image(PdfImageXObject xObject)
Creates anImage
from an image XObject, the representation of an image in PDF syntax.Image(PdfImageXObject xObject, float width)
Creates anImage
from an image XObject, the representation of an image in PDF syntax, with a custom width.Image(PdfImageXObject xObject, float left, float bottom)
Creates anImage
from an image XObject, the representation of an image in PDF syntax, on a fixed position.Image(PdfImageXObject xObject, float left, float bottom, float width)
Creates anImage
from an image XObject, the representation of an image in PDF syntax, with a custom width and on a fixed position.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static ImageData
checkImageType(ImageData image)
AccessibilityProperties
getAccessibilityProperties()
Gets theaccessibility properties
.float
getImageHeight()
Gets height of the image.float
getImageScaledHeight()
Gets scaled height of the image.float
getImageScaledWidth()
Gets scaled width of the image.float
getImageWidth()
Gets width of the image.UnitValue
getMarginBottom()
Gets the current bottom margin width of the image.UnitValue
getMarginLeft()
Gets the current left margin width of the element.UnitValue
getMarginRight()
Gets the current right margin width of the image.UnitValue
getMarginTop()
Gets the current top margin width of the image.ObjectFit
getObjectFit()
Retrieves theObjectFit
mode for the image.UnitValue
getPaddingBottom()
Gets the current bottom padding width of the image.UnitValue
getPaddingLeft()
Gets the current left padding width of the image.UnitValue
getPaddingRight()
Gets the current right padding width of the image.UnitValue
getPaddingTop()
Gets the current top padding width of the image.UnitValue
getWidth()
Gets the width property of the image.PdfXObject
getXObject()
Gets the XObject contained in this image objectprotected IRenderer
makeNewRenderer()
Creates new renderer instance.Image
scale(float horizontalScaling, float verticalScaling)
Scale the image relative to its default size.Image
scaleAbsolute(float fitWidth, float fitHeight)
Scale the image to an absolute size.Image
scaleToFit(float fitWidth, float fitHeight)
Scale the image to an absolute size.Image
setAutoScale(boolean autoScale)
Sets the autoscale property for both width and height.Image
setAutoScaleHeight(boolean autoScale)
Sets the autoscale property for the height of the image.Image
setAutoScaleWidth(boolean autoScale)
Sets the autoscale property for the width of the image.Image
setFixedPosition(float left, float bottom)
Sets values for a absolute repositioning of the Element.Image
setFixedPosition(int pageNumber, float left, float bottom)
Sets values for a absolute repositioning of the Element, on a specific page.Image
setHeight(float height)
Sets the height property of the image, measured in points.Image
setHeight(UnitValue height)
Sets the height property of the image with aUnitValue
.Image
setMarginBottom(float value)
Sets the bottom margin width of the image.Image
setMarginLeft(float value)
Sets the left margin width of the element.Image
setMarginRight(float value)
Sets the right margin width of the image.Image
setMargins(float marginTop, float marginRight, float marginBottom, float marginLeft)
Sets the margins around the image to a series of new widths.Image
setMarginTop(float value)
Sets the top margin width of the image.Image
setMaxHeight(float maxHeight)
Sets the max-height property of the image, measured in points.Image
setMaxHeight(UnitValue maxHeight)
Sets the max-height property of the image with aUnitValue
.Image
setMaxWidth(float maxWidth)
Sets the max-width property of the image, measured in points.Image
setMaxWidth(UnitValue maxWidth)
Sets the max-width property of the image with aUnitValue
.Image
setMinHeight(float minHeight)
Sets the min-height property of the image, measured in points.Image
setMinHeight(UnitValue minHeight)
Sets the min-height property of the image with aUnitValue
.Image
setMinWidth(float minWidth)
Sets the min-width property of the image, measured in points.Image
setMinWidth(UnitValue minWidth)
Sets the min-width property of the image with aUnitValue
.Image
setNeutralRole()
Give this element a neutral role.Image
setObjectFit(ObjectFit objectFit)
Sets an object-fit mode for the image.Image
setPadding(float commonPadding)
Sets all paddings around the image to the same width.Image
setPaddingBottom(float value)
Sets the bottom padding width of the image.Image
setPaddingLeft(float value)
Sets the left padding width of the image.Image
setPaddingRight(float value)
Sets the right padding width of the image.Image
setPaddings(float paddingTop, float paddingRight, float paddingBottom, float paddingLeft)
Sets the paddings around the image to a series of new widths.Image
setPaddingTop(float value)
Sets the top padding width of the image.Image
setRotationAngle(double radAngle)
Sets the rotation radAngle.Image
setWidth(float width)
Sets the width property of the image, measured in points.Image
setWidth(UnitValue width)
Sets the width property of the image with aUnitValue
.-
Methods inherited from class com.itextpdf.layout.element.AbstractElement
addStyle, createRendererSubTree, getChildren, getProperty, getRenderer, hasProperty, isEmpty, setAction, setNextRenderer, setPageNumber
-
Methods inherited from class com.itextpdf.layout.ElementPropertyContainer
deleteOwnProperty, getDefaultProperty, getOwnProperty, getSplitCharacters, getStrokeColor, getStrokeWidth, getTextRenderingMode, hasOwnProperty, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBackgroundImage, setBackgroundImage, setBaseDirection, setBorder, setBorderBottom, setBorderBottomLeftRadius, setBorderBottomRightRadius, setBorderLeft, setBorderRadius, setBorderRight, setBorderTop, setBorderTopLeftRadius, setBorderTopRightRadius, setCharacterSpacing, setDestination, setFixedPosition, setFixedPosition, setFixedPosition, setFixedPosition, setFont, setFontColor, setFontColor, setFontColor, setFontFamily, setFontFamily, setFontKerning, setFontScript, setFontSize, setHorizontalAlignment, setHyphenation, setLineThrough, setOpacity, setProperty, setRelativePosition, setSplitCharacters, setStrokeColor, setStrokeWidth, setTextAlignment, setTextRenderingMode, setUnderline, setUnderline, setUnderline, setUnderline, setWordSpacing, simulateBold, simulateItalic
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.itextpdf.layout.element.IElement
createRendererSubTree, getRenderer, setNextRenderer
-
Methods inherited from interface com.itextpdf.layout.IPropertyContainer
deleteOwnProperty, getDefaultProperty, getOwnProperty, getProperty, hasOwnProperty, hasProperty, setProperty
-
-
-
-
Field Detail
-
xObject
protected PdfXObject xObject
-
tagProperties
protected DefaultAccessibilityProperties tagProperties
-
-
Constructor Detail
-
Image
public Image(PdfImageXObject xObject)
Creates anImage
from an image XObject, the representation of an image in PDF syntax.- Parameters:
xObject
- an internalPdfImageXObject
-
Image
public Image(PdfFormXObject xObject)
Creates anImage
from a form XObject, the representation of a form in PDF syntax.- Parameters:
xObject
- an internalPdfFormXObject
-
Image
public Image(PdfImageXObject xObject, float width)
Creates anImage
from an image XObject, the representation of an image in PDF syntax, with a custom width.- Parameters:
xObject
- an internalPdfImageXObject
width
- a float value
-
Image
public Image(PdfImageXObject xObject, float left, float bottom, float width)
Creates anImage
from an image XObject, the representation of an image in PDF syntax, with a custom width and on a fixed position.- Parameters:
xObject
- an internalPdfImageXObject
left
- a float value representing the horizontal offset of the lower left corner of the imagebottom
- a float value representing the vertical offset of the lower left corner of the imagewidth
- a float value
-
Image
public Image(PdfImageXObject xObject, float left, float bottom)
Creates anImage
from an image XObject, the representation of an image in PDF syntax, on a fixed position.- Parameters:
xObject
- an internalPdfImageXObject
left
- a float value representing the horizontal offset of the lower left corner of the imagebottom
- 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 anImage
from a form XObject, the representation of a form in PDF syntax.- Parameters:
xObject
- an internalPdfFormXObject
left
- a float value representing the horizontal offset of the lower left corner of the formbottom
- a float value representing the vertical offset of the lower left corner of the form
-
Image
public Image(ImageData img)
Creates anImage
from an image resource, read in from a file with the iText I/O module.- Parameters:
img
- an internal representation of theimage resource
-
Image
public Image(ImageData img, float left, float bottom)
Creates anImage
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 theimage resource
left
- a float value representing the horizontal offset of the lower left corner of the imagebottom
- 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 anImage
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 theimage resource
left
- a float value representing the horizontal offset of the lower left corner of the imagebottom
- a float value representing the vertical offset of the lower left corner of the imagewidth
- a float value
-
-
Method Detail
-
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 widthmarginRight
- the new margin right widthmarginBottom
- the new margin bottom widthmarginLeft
- 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 widthpaddingRight
- the new padding right widthpaddingBottom
- the new padding bottom widthpaddingLeft
- 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 imagefitHeight
- 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 imagefitHeight
- 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'sProperty.POSITION
is changed tofixed
.- Parameters:
left
- horizontal position on the pagebottom
- 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'sProperty.POSITION
is changed tofixed
.- Parameters:
pageNumber
- the page where the element must be positionedleft
- horizontal position on the pagebottom
- 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 aUnitValue
.- 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 aUnitValue
.- 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 aUnitValue
.- 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 aUnitValue
.- 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 aUnitValue
.- 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 aUnitValue
.- Parameters:
width
- aUnitValue
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:
UnitValue
-
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 theObjectFit
mode- Returns:
- this image
-
getObjectFit
public ObjectFit getObjectFit()
Retrieves theObjectFit
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
Gets theaccessibility properties
. See alsoIAccessibleElement
.- Specified by:
getAccessibilityProperties
in interfaceIAccessibleElement
- 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 alsoAccessibilityProperties.setRole(String)
.- Returns:
- this Element
-
makeNewRenderer
protected IRenderer makeNewRenderer()
Description copied from class:AbstractElement
Creates new renderer instance.- Specified by:
makeNewRenderer
in classAbstractElement<Image>
- Returns:
- new
IRenderer
-
-