Package com.itextpdf.text
Class Image
- java.lang.Object
-
- com.itextpdf.text.Rectangle
-
- com.itextpdf.text.Image
-
- All Implemented Interfaces:
Indentable
,Spaceable
,Element
,IAccessibleElement
,IAlternateDescription
public abstract class Image extends Rectangle implements Indentable, Spaceable, IAccessibleElement, IAlternateDescription
AnImage
is the representation of a graphic element (JPEG, PNG or GIF) that has to be inserted into the document
-
-
Field Summary
Fields Modifier and Type Field Description protected float
absoluteX
This is the absolute X-position of the image.protected float
absoluteY
This is the absolute Y-position of the image.protected java.util.HashMap<PdfName,PdfObject>
accessibleAttributes
private PdfDictionary
additional
a dictionary with additional informationprotected int
alignment
The alignment of the Image.protected java.lang.String
alt
Text that can be shown instead of the image.protected Annotation
annotation
if the annotation is not null the image will be clickable.static int
AX
This represents a coordinate in the transformation matrix.static int
AY
This represents a coordinate in the transformation matrix.protected int
bpc
The bits per component of the raw image.static int
BX
This represents a coordinate in the transformation matrix.static int
BY
This represents a coordinate in the transformation matrix.protected int
colorspace
this is the colorspace of a jpeg-image.protected int
colortransform
protected int
compressionLevel
The compression level of the content streams.static int
CX
This represents a coordinate in the transformation matrix.static int
CY
This represents a coordinate in the transformation matrix.static int
DEFAULT
this is a kind of image alignment.protected boolean
deflated
Holds value of property deflated.private PdfIndirectReference
directReference
Holds value of property directReference.protected int
dpiX
Holds value of property dpiX.protected int
dpiY
Holds value of property dpiY.static int
DX
This represents a coordinate in the transformation matrix.static int
DY
This represents a coordinate in the transformation matrix.private AccessibleElementId
id
protected Image
imageMask
The image that serves as a mask for this image.protected float
indentationLeft
the indentation to the left.protected float
indentationRight
the indentation to the right.private float
initialRotation
Holds value of property initialRotation.protected boolean
interpolation
Holds value of property interpolation.protected boolean
invert
Image color inversionprotected PdfOCG
layer
Optional Content layer to which we want this Image to belong.static int
LEFT
this is a kind of image alignment.protected boolean
mask
Is this image a mask?static int
MIDDLE
this is a kind of image alignment.protected java.lang.Long
mySerialId
an iText attributed unique id for this image.static int
ORIGINAL_BMP
type of imagestatic int
ORIGINAL_GIF
type of imagestatic int
ORIGINAL_JBIG2
type of imagestatic int
ORIGINAL_JPEG
type of imagestatic int
ORIGINAL_JPEG2000
type of imagestatic int
ORIGINAL_NONE
type of imagestatic int
ORIGINAL_PNG
type of imagestatic int
ORIGINAL_PS
type of imagestatic int
ORIGINAL_TIFF
type of imagestatic int
ORIGINAL_WMF
type of imageprotected byte[]
originalData
Holds value of property originalData.protected int
originalType
Holds value of property originalType.protected float
paddingTop
Padding topprotected float
plainHeight
This is the width of the image without rotation.protected float
plainWidth
This is the width of the image without rotation.protected ICC_Profile
profile
ICC Profile attachedprotected byte[]
rawData
The raw data of the image.static int
RIGHT
this is a kind of image alignment.protected PdfName
role
protected float
rotationRadians
This is the rotation of the image in radians.protected float
scaledHeight
This is the original height of the image taking rotation into account.protected float
scaledWidth
This is the scaled width of the image taking rotation into account.protected boolean
scaleToFitHeight
Indicates if the image should be scaled to fit when the image exceeds the available height.protected boolean
scaleToFitLineWhenOverflow
Indicates if the image should be scaled to fit the line when the image exceeds the available width.(package private) static long
serialId
a static that is used for attributing a unique id to each image.private boolean
smask
Holds value of property smask.protected float
spacingAfter
The spacing after the image.protected float
spacingBefore
The spacing before the image.protected PdfTemplate[]
template
The template to be treated as an image.static int
TEXTWRAP
this is a kind of image alignment.protected int[]
transparency
this is the transparency information of the raw imageprotected int
type
The image type.static int
UNDERLYING
this is a kind of image alignment.protected java.net.URL
url
The URL of the image.private float
widthPercentage
Holds value of property widthPercentage.private float
XYRatio
Holds value of property XYRatio.-
Fields inherited from class com.itextpdf.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, useVariableBorders
-
Fields inherited from interface com.itextpdf.text.Element
ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_JUSTIFIED, ALIGN_JUSTIFIED_ALL, ALIGN_LEFT, ALIGN_MIDDLE, ALIGN_RIGHT, ALIGN_TOP, ALIGN_UNDEFINED, ANCHOR, ANNOTATION, AUTHOR, BODY, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CHAPTER, CHUNK, CREATIONDATE, CREATOR, DIV, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LANGUAGE, LIST, LISTITEM, MARKED, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, SECTION, SUBJECT, TITLE, WRITABLE_DIRECT, YMARK
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description float
getAbsoluteX()
Returns the absolute X position.float
getAbsoluteY()
Returns the absolute Y position.PdfObject
getAccessibleAttribute(PdfName key)
Get the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).java.util.HashMap<PdfName,PdfObject>
getAccessibleAttributes()
Gets all the properties of accessible element.PdfDictionary
getAdditional()
Getter for the dictionary with additional information.int
getAlignment()
Gets the alignment for the image.java.lang.String
getAlt()
Gets the alternative text for the image.Annotation
getAnnotation()
Gets the annotation.int
getBpc()
Gets the bpc for the image.int
getColorspace()
Gets the colorspace for the image.int
getColorTransform()
int
getCompressionLevel()
Returns the compression level used for images written as a compressed stream.PdfIndirectReference
getDirectReference()
Getter for property directReference.int
getDpiX()
Gets the dots-per-inch in the X direction.int
getDpiY()
Gets the dots-per-inch in the Y direction.ICC_Profile
getICCProfile()
Gets the images ICC profile.AccessibleElementId
getId()
Image
getImageMask()
Gets the explicit masking.float
getImageRotation()
Gets the current image rotation in radians.float
getIndentationLeft()
Gets the left indentation.float
getIndentationRight()
Gets the right indentation.float
getInitialRotation()
Getter for property initialRotation.static Image
getInstance(byte[] imgb)
static Image
getInstance(byte[] imgb, boolean recoverFromImageError)
gets an instance of an Imagestatic Image
getInstance(int width, int height, boolean reverseBits, int typeCCITT, int parameters, byte[] data)
Creates an Image with CCITT G3 or G4 compression.static Image
getInstance(int width, int height, boolean reverseBits, int typeCCITT, int parameters, byte[] data, int[] transparency)
Creates an Image with CCITT G3 or G4 compression.static Image
getInstance(int width, int height, byte[] data, byte[] globals)
Creates a JBIG2 Image.static Image
getInstance(int width, int height, int components, int bpc, byte[] data)
Gets an instance of an Image in raw mode.static Image
getInstance(int width, int height, int components, int bpc, byte[] data, int[] transparency)
Gets an instance of an Image in raw mode.static Image
getInstance(Image image)
gets an instance of an Imagestatic Image
getInstance(PdfContentByte cb, java.awt.Image awtImage, float quality)
Gets an instance of a Image from a java.awt.Image.static Image
getInstance(PdfTemplate template)
gets an instance of an Imagestatic Image
getInstance(PdfWriter writer, java.awt.Image awtImage, float quality)
Gets an instance of a Image from a java.awt.Image.static Image
getInstance(PRIndirectReference ref)
Reuses an existing image.static Image
getInstance(java.awt.Image image, java.awt.Color color)
Gets an instance of an Image from a java.awt.Image.static Image
getInstance(java.awt.Image image, java.awt.Color color, boolean forceBW)
Gets an instance of an Image from a java.awt.Image.static Image
getInstance(java.lang.String filename)
Gets an instance of an Image.static Image
getInstance(java.lang.String filename, boolean recoverFromImageError)
static Image
getInstance(java.net.URL url)
static Image
getInstance(java.net.URL url, boolean recoverFromImageError)
Gets an instance of an Image.PdfOCG
getLayer()
Gets the layer this image belongs to.java.lang.Long
getMySerialId()
Returns a serial id for the Image (reuse the same image more than once)byte[]
getOriginalData()
Getter for property originalData.int
getOriginalType()
Getter for property originalType.float
getPaddingTop()
float
getPlainHeight()
Gets the plain height of the image.float
getPlainWidth()
Gets the plain width of the image.byte[]
getRawData()
Gets the raw data for the image.PdfName
getRole()
Gets the role of the accessible element.float
getScaledHeight()
Gets the scaled height of the image.float
getScaledWidth()
Gets the scaled width of the image.protected static java.lang.Long
getSerialId()
Creates a new serial id.float
getSpacingAfter()
Gets the spacing before this image.float
getSpacingBefore()
Gets the spacing before this image.PdfTemplate
getTemplateData()
Gets the template to be used as an image.int[]
getTransparency()
Returns the transparency.java.net.URL
getUrl()
Gets theString
-representation of the reference to the image.float
getWidthPercentage()
Getter for property widthPercentage.float
getXYRatio()
Gets the X/Y pixel dimensionless aspect ratio.boolean
hasAbsoluteX()
Checks if theImages
has to be added at an absolute X position.boolean
hasAbsoluteY()
Checks if theImages
has to be added at an absolute position.boolean
hasICCProfile()
Checks is the image has an ICC profile.boolean
isDeflated()
Getter for property deflated.boolean
isImgRaw()
Returnstrue
if the image is aImgRaw
-object.boolean
isImgTemplate()
Returnstrue
if the image is anImgTemplate
-object.boolean
isInline()
boolean
isInterpolation()
Getter for property interpolation.boolean
isInverted()
Getter for the inverted valueboolean
isJpeg()
Returnstrue
if the image is aJpeg
-object.boolean
isMask()
Returnstrue
if thisImage
is a mask.boolean
isMaskCandidate()
Returnstrue
if thisImage
has the requisites to be a mask.boolean
isNestable()
Checks if this element is nestable.boolean
isScaleToFitHeight()
Gets the value of scaleToFitHeight.boolean
isScaleToFitLineWhenOverflow()
Gets the value of scaleToFitLineWhenOverflow.boolean
isSmask()
Getter for property smask.void
makeMask()
Make thisImage
a mask.float[]
matrix()
Returns the transformation matrix of the image.float[]
matrix(float scalePercentage)
Returns the transformation matrix of the image.void
scaleAbsolute(float newWidth, float newHeight)
Scale the image to an absolute width and an absolute height.void
scaleAbsolute(Rectangle rectangle)
Scale the image to the dimensions of the rectanglevoid
scaleAbsoluteHeight(float newHeight)
Scale the image to an absolute height.void
scaleAbsoluteWidth(float newWidth)
Scale the image to an absolute width.void
scalePercent(float percent)
Scale the image to a certain percentage.void
scalePercent(float percentX, float percentY)
Scale the width and height of an image to a certain percentage.void
scaleToFit(float fitWidth, float fitHeight)
Scales the image so that it fits a certain width and height.void
scaleToFit(Rectangle rectangle)
Scales the images to the dimensions of the rectangle.void
setAbsolutePosition(float absoluteX, float absoluteY)
Sets the absolute position of theImage
.void
setAccessibleAttribute(PdfName key, PdfObject value)
Set the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).void
setAdditional(PdfDictionary additional)
Sets the /Colorspace key.void
setAlignment(int alignment)
Sets the alignment for the image.void
setAlt(java.lang.String alt)
Sets the alternative information for the image.void
setAnnotation(Annotation annotation)
Sets the annotation of this Image.void
setColorTransform(int c)
void
setCompressionLevel(int compressionLevel)
Sets the compression level to be used if the image is written as a compressed stream.void
setDeflated(boolean deflated)
Setter for property deflated.void
setDirectReference(PdfIndirectReference directReference)
Setter for property directReference.void
setDpi(int dpiX, int dpiY)
Sets the dots per inch valuevoid
setId(AccessibleElementId id)
void
setImageMask(Image mask)
Sets the explicit masking.void
setIndentationLeft(float f)
Sets the left indentation.void
setIndentationRight(float f)
Sets the right indentation.void
setInitialRotation(float initialRotation)
Some image formats, like TIFF may present the images rotated that have to be compensated.void
setInterpolation(boolean interpolation)
Sets the image interpolation.void
setInverted(boolean invert)
Sets inverted true or falsevoid
setLayer(PdfOCG layer)
Sets the layer this image belongs to.void
setOriginalData(byte[] originalData)
Setter for property originalData.void
setOriginalType(int originalType)
Setter for property originalType.void
setPaddingTop(float paddingTop)
void
setRole(PdfName role)
Sets the role of the accessiblee element.void
setRotation(float r)
Sets the rotation of the image in radians.void
setRotationDegrees(float deg)
Sets the rotation of the image in degrees.void
setScaleToFitHeight(boolean scaleToFitHeight)
Sets the value of scaleToFitHeightvoid
setScaleToFitLineWhenOverflow(boolean scaleToFitLineWhenOverflow)
Sets the value of scaleToFitLineWhenOverflowvoid
setSmask(boolean smask)
Setter for property smask.void
setSpacingAfter(float spacing)
Sets the spacing after this image.void
setSpacingBefore(float spacing)
Sets the spacing before this image.void
setTemplateData(PdfTemplate template)
Sets data from a PdfTemplatevoid
setTransparency(int[] transparency)
Sets the transparency valuesvoid
setUrl(java.net.URL url)
Sets the url of the imagevoid
setWidthPercentage(float widthPercentage)
Setter for property widthPercentage.void
setXYRatio(float XYRatio)
Sets the X/Y pixel dimensionless aspect ratio.void
simplifyColorspace()
Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray.private PdfObject
simplifyColorspace(PdfArray obj)
Gets a PDF Name from an array or returns the object that was passed.void
tagICC(ICC_Profile profile)
Tags this image with an ICC profile.int
type()
Returns the type.-
Methods inherited from class com.itextpdf.text.Rectangle
cloneNonPositionParameters, disableBorderSide, enableBorderSide, equals, getBackgroundColor, getBorder, getBorderColor, getBorderColorBottom, getBorderColorLeft, getBorderColorRight, getBorderColorTop, getBorderWidth, getBorderWidthBottom, getBorderWidthLeft, getBorderWidthRight, getBorderWidthTop, getBottom, getBottom, getChunks, getGrayFill, getHeight, getLeft, getLeft, getRight, getRight, getRotation, getTop, getTop, getWidth, hasBorder, hasBorders, isContent, isUseVariableBorders, normalize, process, rectangle, rotate, setBackgroundColor, setBorder, setBorderColor, setBorderColorBottom, setBorderColorLeft, setBorderColorRight, setBorderColorTop, setBorderWidth, setBorderWidthBottom, setBorderWidthLeft, setBorderWidthRight, setBorderWidthTop, setBottom, setGrayFill, setLeft, setRight, setRotation, setTop, setUseVariableBorders, softCloneNonPositionParameters, toString
-
-
-
-
Field Detail
-
DEFAULT
public static final int DEFAULT
this is a kind of image alignment.- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
this is a kind of image alignment.- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
this is a kind of image alignment.- See Also:
- Constant Field Values
-
MIDDLE
public static final int MIDDLE
this is a kind of image alignment.- See Also:
- Constant Field Values
-
TEXTWRAP
public static final int TEXTWRAP
this is a kind of image alignment.- See Also:
- Constant Field Values
-
UNDERLYING
public static final int UNDERLYING
this is a kind of image alignment.- See Also:
- Constant Field Values
-
AX
public static final int AX
This represents a coordinate in the transformation matrix.- See Also:
- Constant Field Values
-
AY
public static final int AY
This represents a coordinate in the transformation matrix.- See Also:
- Constant Field Values
-
BX
public static final int BX
This represents a coordinate in the transformation matrix.- See Also:
- Constant Field Values
-
BY
public static final int BY
This represents a coordinate in the transformation matrix.- See Also:
- Constant Field Values
-
CX
public static final int CX
This represents a coordinate in the transformation matrix.- See Also:
- Constant Field Values
-
CY
public static final int CY
This represents a coordinate in the transformation matrix.- See Also:
- Constant Field Values
-
DX
public static final int DX
This represents a coordinate in the transformation matrix.- See Also:
- Constant Field Values
-
DY
public static final int DY
This represents a coordinate in the transformation matrix.- See Also:
- Constant Field Values
-
ORIGINAL_NONE
public static final int ORIGINAL_NONE
type of image- See Also:
- Constant Field Values
-
ORIGINAL_JPEG
public static final int ORIGINAL_JPEG
type of image- See Also:
- Constant Field Values
-
ORIGINAL_PNG
public static final int ORIGINAL_PNG
type of image- See Also:
- Constant Field Values
-
ORIGINAL_GIF
public static final int ORIGINAL_GIF
type of image- See Also:
- Constant Field Values
-
ORIGINAL_BMP
public static final int ORIGINAL_BMP
type of image- See Also:
- Constant Field Values
-
ORIGINAL_TIFF
public static final int ORIGINAL_TIFF
type of image- See Also:
- Constant Field Values
-
ORIGINAL_WMF
public static final int ORIGINAL_WMF
type of image- See Also:
- Constant Field Values
-
ORIGINAL_PS
public static final int ORIGINAL_PS
type of image- See Also:
- Constant Field Values
-
ORIGINAL_JPEG2000
public static final int ORIGINAL_JPEG2000
type of image- See Also:
- Constant Field Values
-
ORIGINAL_JBIG2
public static final int ORIGINAL_JBIG2
type of image- Since:
- 2.1.5
- See Also:
- Constant Field Values
-
type
protected int type
The image type.
-
url
protected java.net.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 java.lang.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 java.lang.Long mySerialId
an iText attributed unique id for this image.
-
role
protected PdfName role
-
id
private AccessibleElementId id
-
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.
-
serialId
static long serialId
a static that is used for attributing a unique id to each image.
-
rotationRadians
protected float rotationRadians
This is the rotation of the image in radians.
-
initialRotation
private float initialRotation
Holds value of property initialRotation.
-
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.
-
paddingTop
protected float paddingTop
Padding top
-
widthPercentage
private float widthPercentage
Holds value of property widthPercentage.
-
scaleToFitLineWhenOverflow
protected boolean scaleToFitLineWhenOverflow
Indicates if the image should be scaled to fit the line when the image exceeds the available width.- Since:
- iText 5.0.6
-
scaleToFitHeight
protected boolean scaleToFitHeight
Indicates if the image should be scaled to fit when the image exceeds the available height.- Since:
- iText 5.4.2
-
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.
-
XYRatio
private float XYRatio
Holds value of property XYRatio.
-
colorspace
protected int colorspace
this is the colorspace of a jpeg-image.
-
colortransform
protected int colortransform
-
invert
protected boolean invert
Image color inversion
-
profile
protected ICC_Profile profile
ICC Profile attached
-
additional
private PdfDictionary additional
a dictionary with additional information
-
mask
protected boolean mask
Is this image a mask?
-
imageMask
protected Image imageMask
The image that serves as a mask for this image.
-
smask
private boolean smask
Holds value of property smask.
-
transparency
protected int[] transparency
this is the transparency information of the raw image
-
-
Constructor Detail
-
Image
public Image(java.net.URL url)
Constructs anImage
-object, using an url .- Parameters:
url
- theURL
where the image can be found.
-
Image
protected Image(Image image)
Constructs anImage
-object, using an url .- Parameters:
image
- another Image object.
-
-
Method Detail
-
getInstance
public static Image getInstance(java.net.URL url) throws BadElementException, java.net.MalformedURLException, java.io.IOException
- Throws:
BadElementException
java.net.MalformedURLException
java.io.IOException
-
getInstance
public static Image getInstance(java.net.URL url, boolean recoverFromImageError) throws BadElementException, java.net.MalformedURLException, java.io.IOException
Gets an instance of an Image.- Parameters:
url
- an URL- Returns:
- an Image
- Throws:
BadElementException
java.net.MalformedURLException
java.io.IOException
-
getInstance
public static Image getInstance(java.lang.String filename) throws BadElementException, java.net.MalformedURLException, java.io.IOException
Gets an instance of an Image.- Parameters:
filename
- a filename- Returns:
- an object of type
Gif
,Jpeg
orPng
- Throws:
BadElementException
java.net.MalformedURLException
java.io.IOException
-
getInstance
public static Image getInstance(java.lang.String filename, boolean recoverFromImageError) throws java.io.IOException, BadElementException
- Throws:
java.io.IOException
BadElementException
-
getInstance
public static Image getInstance(byte[] imgb) throws BadElementException, java.net.MalformedURLException, java.io.IOException
- Throws:
BadElementException
java.net.MalformedURLException
java.io.IOException
-
getInstance
public static Image getInstance(byte[] imgb, boolean recoverFromImageError) throws BadElementException, java.net.MalformedURLException, java.io.IOException
gets an instance of an Image- Parameters:
imgb
- raw image date- Returns:
- an Image object
- Throws:
BadElementException
java.net.MalformedURLException
java.io.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 pixelsheight
- the height of the image in pixelscomponents
- 1,3 or 4 for GrayScale, RGB and CMYKdata
- the image databpc
- bits per component- 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 imageheight
- the height of the imagedata
- the raw image dataglobals
- JBIG2 globals- Returns:
- the Image
- 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 imageheight
- the exact height of the imagereverseBits
- reverses the bits indata
. Bit 0 is swapped with bit 7 and so ontypeCCITT
- the type of compression indata
. It can be CCITTG4, CCITTG31D, CCITTG32Dparameters
- parameters associated with this stream. Possible values are CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFLINE and CCITT_ENDOFBLOCK or a combination of themdata
- 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 imageheight
- the exact height of the imagereverseBits
- reverses the bits indata
. Bit 0 is swapped with bit 7 and so ontypeCCITT
- the type of compression indata
. It can be CCITTG4, CCITTG31D, CCITTG32Dparameters
- parameters associated with this stream. Possible values are CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFLINE and CCITT_ENDOFBLOCK or a combination of themdata
- the image datatransparency
- 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 pixelsheight
- the height of the image in pixelscomponents
- 1,3 or 4 for GrayScale, RGB and CMYKdata
- the image databpc
- bits per componenttransparency
- 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
-
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.
-
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
-
type
public int type()
Returns the type.
-
isNestable
public boolean isNestable()
Description copied from interface:Element
Checks if this element is nestable.- Specified by:
isNestable
in interfaceElement
- Overrides:
isNestable
in classRectangle
- Returns:
- true if this element can be nested inside other elements.
- Since:
- iText 2.0.8
- See Also:
Element.isNestable()
-
isJpeg
public boolean isJpeg()
Returnstrue
if the image is aJpeg
-object.- Returns:
- a
boolean
-
isImgRaw
public boolean isImgRaw()
Returnstrue
if the image is aImgRaw
-object.- Returns:
- a
boolean
-
isImgTemplate
public boolean isImgTemplate()
Returnstrue
if the image is anImgTemplate
-object.- Returns:
- a
boolean
-
getUrl
public java.net.URL getUrl()
Gets theString
-representation of the reference to the image.- Returns:
- a
String
-
setUrl
public void setUrl(java.net.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.- Returns:
- a value
-
setAlignment
public void setAlignment(int alignment)
Sets the alignment for the image.- Parameters:
alignment
- the alignment
-
getAlt
public java.lang.String getAlt()
Gets the alternative text for the image.- Specified by:
getAlt
in interfaceIAlternateDescription
- Returns:
- a
String
-
setAlt
public void setAlt(java.lang.String alt)
Sets the alternative information for the image.- Specified by:
setAlt
in interfaceIAlternateDescription
- Parameters:
alt
- the alternative information
-
setAbsolutePosition
public void setAbsolutePosition(float absoluteX, float absoluteY)
Sets the absolute position of theImage
.- Parameters:
absoluteX
-absoluteY
-
-
hasAbsoluteX
public boolean hasAbsoluteX()
Checks if theImages
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 theImages
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(Rectangle rectangle)
Scale the image to the dimensions of the rectangle- Parameters:
rectangle
- dimensions to scale the Image
-
scaleAbsolute
public void scaleAbsolute(float newWidth, float newHeight)
Scale the image to an absolute width and an absolute height.- Parameters:
newWidth
- the new widthnewHeight
- 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 widthpercentY
- the scaling percentage of the height
-
scaleToFit
public void scaleToFit(Rectangle rectangle)
Scales the images to the dimensions of the rectangle.- Parameters:
rectangle
- the dimensions to fit
-
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 fitfitHeight
- 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]
-
matrix
public float[] matrix(float scalePercentage)
Returns the transformation matrix of the image.- Returns:
- an array [AX, AY, BX, BY, CX, CY, DX, DY]
-
getSerialId
protected static java.lang.Long getSerialId()
Creates a new serial id.- Returns:
- the new serialId
-
getMySerialId
public java.lang.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.- Specified by:
getIndentationLeft
in interfaceIndentable
- Returns:
- the left indentation
-
setIndentationLeft
public void setIndentationLeft(float f)
Sets the left indentation.- Specified by:
setIndentationLeft
in interfaceIndentable
- Parameters:
f
-
-
getIndentationRight
public float getIndentationRight()
Gets the right indentation.- Specified by:
getIndentationRight
in interfaceIndentable
- Returns:
- the right indentation
-
setIndentationRight
public void setIndentationRight(float f)
Sets the right indentation.- Specified by:
setIndentationRight
in interfaceIndentable
- Parameters:
f
-
-
getSpacingBefore
public float getSpacingBefore()
Gets the spacing before this image.- Specified by:
getSpacingBefore
in interfaceSpaceable
- Returns:
- the spacing
-
setSpacingBefore
public void setSpacingBefore(float spacing)
Sets the spacing before this image.- Specified by:
setSpacingBefore
in interfaceSpaceable
- Parameters:
spacing
- the new spacing
-
getSpacingAfter
public float getSpacingAfter()
Gets the spacing before this image.- Specified by:
getSpacingAfter
in interfaceSpaceable
- Returns:
- the spacing
-
setSpacingAfter
public void setSpacingAfter(float spacing)
Sets the spacing after this image.- Specified by:
setSpacingAfter
in interfaceSpaceable
- Parameters:
spacing
- the new spacing
-
getPaddingTop
public float getPaddingTop()
- Specified by:
getPaddingTop
in interfaceSpaceable
-
setPaddingTop
public void setPaddingTop(float paddingTop)
- Specified by:
setPaddingTop
in interfaceSpaceable
-
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.
-
isScaleToFitLineWhenOverflow
public boolean isScaleToFitLineWhenOverflow()
Gets the value of scaleToFitLineWhenOverflow.- Returns:
- true if the image size has to scale to the available width
- Since:
- iText 5.0.6
-
setScaleToFitLineWhenOverflow
public void setScaleToFitLineWhenOverflow(boolean scaleToFitLineWhenOverflow)
Sets the value of scaleToFitLineWhenOverflow- Parameters:
scaleToFitLineWhenOverflow
- true if you want the image to scale to the available width- Since:
- iText 5.0.6
-
isScaleToFitHeight
public boolean isScaleToFitHeight()
Gets the value of scaleToFitHeight.- Returns:
- true if the image size has to scale to the available height
- Since:
- iText 5.4.2
-
setScaleToFitHeight
public void setScaleToFitHeight(boolean scaleToFitHeight)
Sets the value of scaleToFitHeight- Parameters:
scaleToFitHeight
- true if you want the image to scale to the available height- Since:
- iText 5.4.2
-
setAnnotation
public void setAnnotation(Annotation annotation)
Sets the annotation of this Image.- Parameters:
annotation
- the annotation
-
getAnnotation
public Annotation getAnnotation()
Gets the annotation.- Returns:
- the annotation that is linked to this image
-
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 coordinatesdpiY
- 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
-
setColorTransform
public void setColorTransform(int c)
-
getColorTransform
public int getColorTransform()
-
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()
Returnstrue
if thisImage
is a mask.- Returns:
true
if thisImage
is a mask
-
makeMask
public void makeMask() throws DocumentException
Make thisImage
a mask.- Throws:
DocumentException
- if thisImage
can not be a mask
-
isMaskCandidate
public boolean isMaskCandidate()
Returnstrue
if thisImage
has the requisites to be a mask.- Returns:
true
if thisImage
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
-
getAccessibleAttribute
public PdfObject getAccessibleAttribute(PdfName key)
Description copied from interface:IAccessibleElement
Get the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).- Specified by:
getAccessibleAttribute
in interfaceIAccessibleElement
- Returns:
-
setAccessibleAttribute
public void setAccessibleAttribute(PdfName key, PdfObject value)
Description copied from interface:IAccessibleElement
Set the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).- Specified by:
setAccessibleAttribute
in interfaceIAccessibleElement
-
getAccessibleAttributes
public java.util.HashMap<PdfName,PdfObject> getAccessibleAttributes()
Description copied from interface:IAccessibleElement
Gets all the properties of accessible element.- Specified by:
getAccessibleAttributes
in interfaceIAccessibleElement
- Returns:
-
getRole
public PdfName getRole()
Description copied from interface:IAccessibleElement
Gets the role of the accessible element.- Specified by:
getRole
in interfaceIAccessibleElement
- Returns:
-
setRole
public void setRole(PdfName role)
Description copied from interface:IAccessibleElement
Sets the role of the accessiblee element. Set role tonull
if you don't want to tag this element. Note that all child elements won't also be tagged.- Specified by:
setRole
in interfaceIAccessibleElement
-
getId
public AccessibleElementId getId()
- Specified by:
getId
in interfaceIAccessibleElement
-
setId
public void setId(AccessibleElementId id)
- Specified by:
setId
in interfaceIAccessibleElement
-
isInline
public boolean isInline()
- Specified by:
isInline
in interfaceIAccessibleElement
-
getInstance
public static Image getInstance(java.awt.Image image, java.awt.Color color, boolean forceBW) throws BadElementException, java.io.IOException
Gets an instance of an Image from a java.awt.Image.- Parameters:
image
- thejava.awt.Image
to convertcolor
- if different fromnull
the transparency pixels are replaced by this colorforceBW
- iftrue
the image is treated as black and white- Returns:
- an object of type
ImgRaw
- Throws:
BadElementException
- on errorjava.io.IOException
- on error
-
getInstance
public static Image getInstance(java.awt.Image image, java.awt.Color color) throws BadElementException, java.io.IOException
Gets an instance of an Image from a java.awt.Image.- Parameters:
image
- thejava.awt.Image
to convertcolor
- if different fromnull
the transparency pixels are replaced by this color- Returns:
- an object of type
ImgRaw
- Throws:
BadElementException
- on errorjava.io.IOException
- on error
-
getInstance
public static Image getInstance(PdfWriter writer, java.awt.Image awtImage, float quality) throws BadElementException, java.io.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
- thePdfWriter
object to which the image will be addedawtImage
- thejava.awt.Image
to convertquality
- a float value between 0 and 1- Returns:
- an object of type
PdfTemplate
- Throws:
BadElementException
- on errorjava.io.IOException
-
getInstance
public static Image getInstance(PdfContentByte cb, java.awt.Image awtImage, float quality) throws BadElementException, java.io.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
- thePdfContentByte
object to which the image will be addedawtImage
- thejava.awt.Image
to convertquality
- a float value between 0 and 1- Returns:
- an object of type
PdfTemplate
- Throws:
BadElementException
- on errorjava.io.IOException
-
-