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
ConstructorsConstructorDescriptionPdfImageXObject(ImageData image) Creates Image XObject by image.PdfImageXObject(ImageData image, PdfImageXObject imageMask) Creates Image XObject by image.PdfImageXObject(PdfStream pdfStream) CreatePdfImageXObjectinstance byPdfStream. -
Method Summary
Modifier and TypeMethodDescriptioncopyTo(PdfDocument document) Copy Image XObject to the specified document.voidflush()To manually flush aPdfObjectbehind this wrapper, you have to ensure that this object is added to the document, i.e.Gets image bytes, wrapped with buffered image.floatGets height of image,Heightkey.byte[]Gets decoded image bytes.byte[]getImageBytes(boolean decoded) Gets image bytes.floatgetWidth()Gets width of image,Widthkey.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, setLayerMethods 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-ImageDatawith actual image data.
-
PdfImageXObject
Creates Image XObject by image.- Parameters:
-
image-ImageDatawith actual image data. -
imageMask-PdfImageXObjectwith image mask.
-
PdfImageXObject
CreatePdfImageXObjectinstance byPdfStream. Note, this constructor doesn't perform any additional checks- Parameters:
-
pdfStream-PdfStreamwith Image XObject. - See Also:
-
-
Method Details
-
getWidth
public float getWidth()Gets width of image,Widthkey.- Overrides:
-
getWidthin classPdfXObject - Returns:
- float value.
-
getHeight
public float getHeight()Gets height of image,Heightkey.- Overrides:
-
getHeightin classPdfXObject - Returns:
- float value.
-
flush
public void flush()To manually flush aPdfObjectbehind 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:
-
flushin 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:
-
BufferedImageimage. - 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.JBIG2DecodeandPdfName.JPXDecodefilters 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.PNGas 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
Stringwith 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.
-