Package org.openpdf.text
Class Image
java.lang.Object
org.openpdf.text.Rectangle
org.openpdf.text.Image
- All Implemented Interfaces:
Element
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 Summary
FieldsModifier and TypeFieldDescriptionprotected floatThis is the absolute X-position of the image.protected floatThis is the absolute Y-position of the image.protected intThe alignment of the Image.protected StringText that can be shown instead of the image.static final intThis represents a coordinate in the transformation matrix.static final intThis represents a coordinate in the transformation matrix.protected intThe bits per component of the raw image.static final intThis represents a coordinate in the transformation matrix.static final intThis represents a coordinate in the transformation matrix.protected intthis is the colorspace of a jpeg-image.protected intThe compression level of the content streams.static final intThis represents a coordinate in the transformation matrix.static final intThis represents a coordinate in the transformation matrix.static final intImage alignment: Default alignment (same as LEFT).protected booleanHolds value of property deflated.protected intHolds value of property dpiX.protected intHolds value of property dpiY.static final intThis represents a coordinate in the transformation matrix.static final intThis represents a coordinate in the transformation matrix.protected ImageThe image that serves as a mask for this image.protected floatthe indentation to the left.protected floatthe indentation to the right.protected booleanHolds value of property interpolation.protected booleanImage color inversionstatic final intImage alignment: Left-align the image.protected booleanIs this image a mask?protected Longan iText attributed unique id for this image.static final inttype of imageprotected byte[]Holds value of property originalData.protected intHolds value of property originalType.protected floatThis is the width of the image without rotation.protected floatThis is the width of the image without rotation.protected byte[]The raw data of the image.static final intImage alignment: Right-align the image.protected floatThis is the rotation of the image in radians.protected floatThis is the original height of the image taking rotation into account.protected floatThis is the scaled width of the image taking rotation into account.protected floatThe spacing after the image.protected floatThe spacing before the image.protected PdfTemplate[]The template to be treated as an image.protected int[]this is the transparency information of the raw imageprotected intThe image type.protected URLThe URL of the image.Fields inherited from class org.openpdf.text.Rectangle
backgroundColor, border, borderColor, borderColorBottom, borderColorLeft, borderColorRight, borderColorTop, borderWidth, borderWidthBottom, borderWidthLeft, borderWidthRight, borderWidthTop, BOTTOM, BOX, llx, lly, NO_BORDER, rotation, TOP, UNDEFINED, urx, ury, useVariableBordersFields inherited from interface org.openpdf.text.Element
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, AUTHOR, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CREATIONDATE, CREATOR, HEADER, IMGRAW, IMGTEMPLATE, KEYWORDS, MARKED, MODIFICATIONDATE, PRODUCER, RECTANGLE, SUBJECT, TABLE, TITLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatReturns the absolute X position.floatReturns the absolute Y position.Getter for the dictionary with additional information.intgetBpc()Gets the bpc for the image.intGets the colorspace for the image.intReturns the compression level used for images written as a compressed stream.Getter for property directReference.Gets the explicit masking.static ImagegetInstance(int width, int height, int components, int bpc, byte[] data) Gets an instance of an Image in raw mode.static ImagegetInstance(int width, int height, int components, int bpc, byte[] data, int[] transparency) Gets an instance of an Image in raw mode.Returns a serial id for the Image (reuse the same image more than once)byte[]Gets the raw data for the image.protected static LongCreates a new serial id.Gets the template to be used as an image.int[]Returns the transparency.booleanChecks if theImageshas to be added at an absolute position.booleanGetter for property deflated.booleanisImgRaw()Returnstrueif the image is aImgRaw-object.booleanReturnstrueif the image is anImgTemplate-object.booleanGetter for property interpolation.booleanGetter for the inverted valuebooleanisMask()Returnstrueif thisImageis a mask.booleanReturnstrueif thisImagehas the requisites to be a mask.booleanChecks if this element is nestable.booleanisSmask()Getter for property smask.voidmakeMask()Make thisImagea mask.float[]matrix()Returns the transformation matrix of the image.voidsetAbsolutePosition(float absoluteX, float absoluteY) Sets the absolute position of theImage.voidsetCompressionLevel(int compressionLevel) Sets the compression level to be used if the image is written as a compressed stream.voidsetImageMask(Image mask) Sets the explicit masking.inttype()Returns the type.Methods inherited from class org.openpdf.text.Rectangle
cloneNonPositionParameters, getBackgroundColor, getBorderColor, getBorderColorBottom, getBorderColorLeft, getBorderColorRight, getBorderColorTop, getBorderWidth, getBorderWidthBottom, getBorderWidthLeft, getBorderWidthRight, getBorderWidthTop, getBottom, getHeight, getLeft, getRight, getRotation, getTop, getWidth, hasBorder, hasBorders, isContent, isUseVariableBorders, setBottom, setLeft, setRight, setTop, toString
-
Field Details
-
DEFAULT
public static final int DEFAULTImage alignment: Default alignment (same as LEFT). The image will be placed on the left side of the page.- See Also:
-
RIGHT
public static final int RIGHTImage alignment: Right-align the image. The image will be placed on the right side of the page. Can be combined with TEXTWRAP or UNDERLYING using bitwise OR. Example:image.setAlignment(Image.RIGHT | Image.TEXTWRAP);- See Also:
-
LEFT
public static final int LEFTImage 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:
-
AX
public static final int AXThis represents a coordinate in the transformation matrix.- See Also:
-
AY
public static final int AYThis represents a coordinate in the transformation matrix.- See Also:
-
BX
public static final int BXThis represents a coordinate in the transformation matrix.- See Also:
-
BY
public static final int BYThis represents a coordinate in the transformation matrix.- See Also:
-
CX
public static final int CXThis represents a coordinate in the transformation matrix.- See Also:
-
CY
public static final int CYThis represents a coordinate in the transformation matrix.- See Also:
-
DX
public static final int DXThis represents a coordinate in the transformation matrix.- See Also:
-
DY
public static final int DYThis represents a coordinate in the transformation matrix.- See Also:
-
ORIGINAL_NONE
public static final int ORIGINAL_NONEtype of image- See Also:
-
type
protected int typeThe image type. -
url
The URL of the image. -
rawData
protected byte[] rawDataThe raw data of the image. -
bpc
protected int bpcThe bits per component of the raw image. It also flags a CCITT image. -
template
The template to be treated as an image. -
alignment
protected int alignmentThe alignment of the Image. -
alt
Text that can be shown instead of the image. -
absoluteX
protected float absoluteXThis is the absolute X-position of the image. -
absoluteY
protected float absoluteYThis is the absolute Y-position of the image. -
plainWidth
protected float plainWidthThis is the width of the image without rotation. -
plainHeight
protected float plainHeightThis is the width of the image without rotation. -
scaledWidth
protected float scaledWidthThis is the scaled width of the image taking rotation into account. -
scaledHeight
protected float scaledHeightThis is the original height of the image taking rotation into account. -
compressionLevel
protected int compressionLevelThe compression level of the content streams.- Since:
- 2.1.3
-
mySerialId
an iText attributed unique id for this image. -
rotationRadians
protected float rotationRadiansThis is the rotation of the image in radians. -
indentationLeft
protected float indentationLeftthe indentation to the left. -
indentationRight
protected float indentationRightthe indentation to the right. -
spacingBefore
protected float spacingBeforeThe spacing before the image. -
spacingAfter
protected float spacingAfterThe spacing after the image. -
interpolation
protected boolean interpolationHolds value of property interpolation. -
originalType
protected int originalTypeHolds value of property originalType. -
originalData
protected byte[] originalDataHolds value of property originalData. -
deflated
protected boolean deflatedHolds value of property deflated. -
dpiX
protected int dpiXHolds value of property dpiX. -
dpiY
protected int dpiYHolds value of property dpiY. -
colorspace
protected int colorspacethis is the colorspace of a jpeg-image. -
invert
protected boolean invertImage color inversion -
mask
protected boolean maskIs this image a mask? -
imageMask
The image that serves as a mask for this image. -
transparency
protected int[] transparencythis is the transparency information of the raw image
-
-
Constructor Details
-
Image
Constructs anImage-object, using an url .- Parameters:
url- theURLwhere the image can be found.
-
Image
Constructs anImage-object, using an url .- Parameters:
image- another Image object.
-
-
Method Details
-
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 pixelsheight- the height of the image in pixelscomponents- 1,3 or 4 for GrayScale, RGB and CMYKbpc- bits per componentdata- the image data- Returns:
- an object of type
ImgRaw - Throws:
BadElementException- on error
-
getSerialId
Creates a new serial id.- Returns:
- a new serial id
-
getDirectReference
Getter for property directReference.- Returns:
- Value of property directReference.
-
type
public int type()Returns the type. -
isNestable
public boolean isNestable()Description copied from interface:ElementChecks if this element is nestable.- Specified by:
isNestablein interfaceElement- Overrides:
isNestablein classRectangle- Returns:
- true if this element can be nested inside other elements.
- Since:
- iText 2.0.8
- See Also:
-
isImgRaw
public boolean isImgRaw()Returnstrueif the image is aImgRaw-object.- Returns:
- a
boolean
-
isImgTemplate
public boolean isImgTemplate()Returnstrueif the image is anImgTemplate-object.- Returns:
- a
boolean
-
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
Gets the template to be used as an image.Remark: this only makes sense for Images of the type
ImgTemplate.- Returns:
- the template
-
setAbsolutePosition
public void setAbsolutePosition(float absoluteX, float absoluteY) Sets the absolute position of theImage.- Parameters:
absoluteX- absolute x positionabsoluteY- absolute y position
-
getAbsoluteX
public float getAbsoluteX()Returns the absolute X position.- Returns:
- a position
-
hasAbsoluteY
public boolean hasAbsoluteY()Checks if theImageshas to be added at an absolute position.- Returns:
- a boolean
-
getAbsoluteY
public float getAbsoluteY()Returns the absolute Y position.- Returns:
- a position
-
matrix
public float[] matrix()Returns the transformation matrix of the image.- Returns:
- an array [AX, AY, BX, BY, CX, CY, DX, DY]
-
getMySerialId
Returns a serial id for the Image (reuse the same image more than once)- Returns:
- a serialId
-
isInterpolation
public boolean isInterpolation()Getter for property interpolation.- Returns:
- Value of property interpolation.
-
isDeflated
public boolean isDeflated()Getter for property deflated.- Returns:
- Value of property deflated.
-
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
-
getAdditional
Getter for the dictionary with additional information.- Returns:
- a PdfDictionary with additional information.
-
isMask
public boolean isMask()Returnstrueif thisImageis a mask.- Returns:
trueif thisImageis a mask
-
makeMask
Make thisImagea mask.- Throws:
DocumentException- if thisImagecan not be a mask
-
isMaskCandidate
public boolean isMaskCandidate()Returnstrueif thisImagehas the requisites to be a mask.- Returns:
trueif thisImagecan be a mask
-
getImageMask
Gets the explicit masking.- Returns:
- the explicit masking
-
setImageMask
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.
-
getTransparency
public int[] getTransparency()Returns the transparency.- Returns:
- 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
-
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 pixelsheight- the height of the image in pixelscomponents- 1,3 or 4 for GrayScale, RGB and CMYKbpc- bits per componentdata- the image datatransparency- transparency information in the Mask format of the image dictionary- Returns:
- an object of type
ImgRaw - Throws:
BadElementException- on error
-