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
-
public class PdfImageXObject extends PdfXObject
A wrapper for Image XObject. ISO 32000-1, 8.9 Images.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
PdfImageXObject.PngChromaticitiesHelper
-
Constructor Summary
Constructors Constructor Description PdfImageXObject(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static ImageData
checkImageType(ImageData image)
PdfImageXObject
copyTo(PdfDocument document)
Copy Image XObject to the specified document.private static PdfArray
createArray(PdfStream stream, java.lang.Object[] objects)
private static PdfDictionary
createDictionaryFromMap(PdfStream stream, java.util.Map<java.lang.String,java.lang.Object> parms)
private static PdfStream
createPdfStream(ImageData image, PdfImageXObject imageMask)
void
flush()
To manually flush aPdfObject
behind this wrapper, you have to ensure that this object is added to the document, i.e.java.awt.image.BufferedImage
getBufferedImage()
Gets image bytes, wrapped with buffered image.private static PdfObject
getColorSpaceInfo(PngImageData pngImageData)
float
getHeight()
Gets height of image,Height
key.byte[]
getImageBytes()
Gets decoded image bytes.byte[]
getImageBytes(boolean decoded)
Gets image bytes.float
getWidth()
Gets width of image,Width
key.java.lang.String
identifyImageFileExtension()
Identifies recommended file extension to store the bytes of thisPdfImageXObject
.ImageType
identifyImageType()
Identifies the type of the image that is stored in the bytes of thisPdfImageXObject
.private float
initHeightField()
private float
initWidthField()
PdfImageXObject
put(PdfName key, PdfObject value)
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 Detail
-
PdfImageXObject
public PdfImageXObject(ImageData image)
Creates Image XObject by image.- Parameters:
image
-ImageData
with actual image data.
-
PdfImageXObject
public PdfImageXObject(ImageData image, PdfImageXObject imageMask)
Creates Image XObject by image.- Parameters:
image
-ImageData
with actual image data.imageMask
-PdfImageXObject
with image mask.
-
PdfImageXObject
public PdfImageXObject(PdfStream pdfStream)
CreatePdfImageXObject
instance byPdfStream
. Note, this constructor doesn't perform any additional checks- Parameters:
pdfStream
-PdfStream
with Image XObject.- See Also:
PdfXObject.makeXObject(PdfStream)
-
-
Method Detail
-
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
public PdfImageXObject copyTo(PdfDocument document)
Copy Image XObject to the specified document.- Parameters:
document
- target document- Returns:
- just created instance of
PdfImageXObject
.
-
getBufferedImage
public java.awt.image.BufferedImage getBufferedImage() throws java.io.IOException
Gets image bytes, wrapped with buffered image.- Returns:
BufferedImage
image.- Throws:
java.io.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
public ImageType 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
public java.lang.String 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:
identifyImageType()
-
put
public PdfImageXObject put(PdfName key, PdfObject value)
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 overridevalue
- the value to associate with the specified key- Returns:
- object itself.
-
initWidthField
private float initWidthField()
-
initHeightField
private float initHeightField()
-
createPdfStream
private static PdfStream createPdfStream(ImageData image, PdfImageXObject imageMask)
-
createDictionaryFromMap
private static PdfDictionary createDictionaryFromMap(PdfStream stream, java.util.Map<java.lang.String,java.lang.Object> parms)
-
getColorSpaceInfo
private static PdfObject getColorSpaceInfo(PngImageData pngImageData)
-
-