Package com.itextpdf.kernel.pdf.xobject
Class PdfImageXObject
java.lang.Object
com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfStream>
com.itextpdf.kernel.pdf.xobject.PdfXObject
com.itextpdf.kernel.pdf.xobject.PdfImageXObject
A wrapper for Image XObject. ISO 32000-1, 8.9 Images.
-
Constructor Summary
ConstructorDescriptionPdfImageXObject
(ImageData image) Creates Image XObject by image.PdfImageXObject
(ImageData image, PdfImageXObject imageMask) Creates Image XObject by image.PdfImageXObject
(PdfStream pdfStream) CreatePdfImageXObject
instance byPdfStream
. -
Method Summary
Modifier and TypeMethodDescriptioncopyTo
(PdfDocument document) Copy Image XObject to the specified document.void
flush()
To manually flush aPdfObject
behind this wrapper, you have to ensure that this object is added to the document, i.e.Gets image bytes, wrapped with buffered image.float
Gets height of image,Height
key.byte[]
Gets decoded image bytes.byte[]
getImageBytes
(boolean decoded) Gets image bytes.float
getWidth()
Gets width of image,Width
key.Identifies recommended file extension to store the bytes of thisPdfImageXObject
.Identifies the type of the image that is stored in the bytes of thisPdfImageXObject
.Puts the value into Image XObject dictionary and associates it with the specified key.Methods inherited from class com.itextpdf.kernel.pdf.xobject.PdfXObject
addAssociatedFile, calculateProportionallyFitRectangleWithHeight, calculateProportionallyFitRectangleWithWidth, getAssociatedFiles, isWrappedObjectMustBeIndirect, makeXObject, setLayer
Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
Constructor Details
-
PdfImageXObject
Creates Image XObject by image.- Parameters:
-
image
-ImageData
with actual image data.
-
PdfImageXObject
Creates Image XObject by image.- Parameters:
-
image
-ImageData
with actual image data. -
imageMask
-PdfImageXObject
with image mask.
-
PdfImageXObject
CreatePdfImageXObject
instance byPdfStream
. Note, this constructor doesn't perform any additional checks- Parameters:
-
pdfStream
-PdfStream
with Image XObject. - See Also:
-
-
Method Details
-
getWidth
public float getWidth()Gets width of image,Width
key.- Overrides:
-
getWidth
in classPdfXObject
- Returns:
- float value.
-
getHeight
public float getHeight()Gets height of image,Height
key.- Overrides:
-
getHeight
in classPdfXObject
- Returns:
- float value.
-
flush
public void flush()To manually flush aPdfObject
behind this wrapper, you have to ensure that this object is added to the document, i.e. it has an indirect reference. Basically this means that before flushing you need to explicitly callPdfObjectWrapper.makeIndirect(PdfDocument)
. For example: wrapperInstance.makeIndirect(document).flush(); Note, that not every wrapper require this, only those that have such warning in documentation.- Overrides:
-
flush
in classPdfObjectWrapper<PdfStream>
-
copyTo
Copy Image XObject to the specified document.- Parameters:
-
document
- target document - Returns:
-
just created instance of
PdfImageXObject
.
-
getBufferedImage
Gets image bytes, wrapped with buffered image.- Returns:
-
BufferedImage
image. - Throws:
-
IOException
- if an error occurs during reading.
-
getImageBytes
public byte[] getImageBytes()Gets decoded image bytes.- Returns:
- byte array.
-
getImageBytes
public byte[] getImageBytes(boolean decoded) Gets image bytes. Note,PdfName.DCTDecode
,PdfName.JBIG2Decode
andPdfName.JPXDecode
filters will be ignored.- Parameters:
-
decoded
- iftrue
, decodes stream bytes. - Returns:
- byte array.
-
identifyImageType
Identifies the type of the image that is stored in the bytes of thisPdfImageXObject
. Note that this has nothing to do with the original type of the image. For instance, the return value of this method will never beImageType.PNG
as we lose this information when converting a PNG image into something that can be put into a PDF file. The possible values are:ImageType.JPEG
,ImageType.JPEG2000
,ImageType.JBIG2
,ImageType.TIFF
,ImageType.PNG
- Returns:
- the identified type of image
-
identifyImageFileExtension
Identifies recommended file extension to store the bytes of thisPdfImageXObject
. Possible values are: 'png', 'jpg', 'jp2', 'tif', 'jbig2'. This extension can later be used together with the result ofgetImageBytes()
.- Returns:
-
a
String
with recommended file extension - See Also:
-
put
Puts the value into Image XObject dictionary and associates it with the specified key. If the key is already present, it will override the old value with the specified one.- Parameters:
-
key
- key to insert or to override -
value
- the value to associate with the specified key - Returns:
- object itself.
-