public final class PDImageXObject extends PDXObject implements PDImage
| Constructor and Description |
|---|
PDImageXObject(PDDocument document)
Creates an Image XObject in the given document.
|
PDImageXObject(PDDocument document,
InputStream encodedStream,
COSBase cosFilter,
int width,
int height,
int bitsPerComponent,
PDColorSpace initColorSpace)
Creates an Image XObject in the given document using the given filtered stream.
|
PDImageXObject(PDStream stream,
PDResources resources)
Creates an Image XObject with the given stream as its contents and current color spaces.
|
| Modifier and Type | Method and Description |
|---|---|
static PDImageXObject |
createFromFile(String imagePath,
PDDocument doc)
Create a PDImageXObject from an image file, see
createFromFileByExtension(File, PDDocument) for
more details. |
static PDImageXObject |
createFromFileByContent(File file,
PDDocument doc)
Create a PDImageXObject from an image file.
|
static PDImageXObject |
createFromFileByExtension(File file,
PDDocument doc)
Create a PDImageXObject from an image file.
|
InputStream |
createInputStream()
Returns an InputStream containing the image data, irrespective of whether this is an
inline image or an image XObject.
|
InputStream |
createInputStream(List<String> stopFilters)
Returns an InputStream containing the image data, irrespective of whether this is an
inline image or an image XObject.
|
static PDImageXObject |
createThumbnail(COSStream cosStream)
Creates a thumbnail Image XObject from the given COSBase and name.
|
int |
getBitsPerComponent()
Returns bits per component of this image, or -1 if one has not been set.
|
COSArray |
getColorKeyMask()
Returns the color key mask array associated with this image, or null if there is none.
|
PDColorSpace |
getColorSpace()
Returns the image's color space.
|
COSArray |
getDecode()
Returns the decode array.
|
int |
getHeight()
Returns height of this image, or -1 if one has not been set.
|
BufferedImage |
getImage()
Returns the content of this image as an AWT buffered image with an (A)RGB color space.
|
boolean |
getInterpolate()
Returns true if the image should be interpolated when rendered.
|
PDImageXObject |
getMask()
Returns the Mask Image XObject associated with this image, or null if there is none.
|
PDMetadata |
getMetadata()
Returns the metadata associated with this XObject, or null if there is none.
|
BufferedImage |
getOpaqueImage()
Returns an RGB buffered image containing the opaque image stream without any masks applied.
|
PDImageXObject |
getSoftMask()
Returns the Soft Mask Image XObject associated with this image, or null if there is none.
|
BufferedImage |
getStencilImage(Paint paint)
Returns an ARGB image filled with the given paint and using this image as a mask.
|
int |
getStructParent()
Returns the key of this XObject in the structural parent tree.
|
String |
getSuffix()
This will get the suffix for this image type, e.g. jpg/png.
|
int |
getWidth()
Returns the width of this image, or -1 if one has not been set.
|
boolean |
isEmpty()
Returns true if the image has no data.
|
boolean |
isStencil()
Returns true if the image is a stencil mask.
|
void |
setBitsPerComponent(int bpc)
Set the number of bits per component.
|
void |
setColorSpace(PDColorSpace cs)
Sets the color space for this image.
|
void |
setDecode(COSArray decode)
Sets the decode array.
|
void |
setHeight(int h)
Sets the height of the image.
|
void |
setInterpolate(boolean value)
Sets the Interpolate flag, true for high-quality image scaling.
|
void |
setMetadata(PDMetadata meta)
Sets the metadata associated with this XObject, or null if there is none.
|
void |
setStencil(boolean isStencil)
Sets whether or not the image is a stencil.
|
void |
setStructParent(int key)
Sets the key of this XObject in the structural parent tree.
|
void |
setWidth(int w)
Sets the width of the image.
|
createXObject, getCOSObject, getCOSStream, getPDStream, getStreamclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetCOSObjectpublic PDImageXObject(PDDocument document) throws IOException
document - the current documentIOException - if there is an error creating the XObject.public PDImageXObject(PDDocument document, InputStream encodedStream, COSBase cosFilter, int width, int height, int bitsPerComponent, PDColorSpace initColorSpace) throws IOException
document - the current documentencodedStream - an encoded stream of image datacosFilter - the filter or a COSArray of filterswidth - the image widthheight - the image heightbitsPerComponent - the bits per componentinitColorSpace - the color spaceIOException - if there is an error creating the XObject.public PDImageXObject(PDStream stream, PDResources resources) throws IOException
stream - the XObject stream to readresources - the current resourcesIOException - if there is an error creating the XObject.public static PDImageXObject createThumbnail(COSStream cosStream) throws IOException
cosStream - the COS streamIOException - if there is an error creating the XObject.public static PDImageXObject createFromFile(String imagePath, PDDocument doc) throws IOException
createFromFileByExtension(File, PDDocument) for
more details.imagePath - the image file path.doc - the document that shall use this PDImageXObject.IOException - if there is an error when reading the file or creating the
PDImageXObject, or if the image type is not supported.public static PDImageXObject createFromFileByExtension(File file, PDDocument doc) throws IOException
JPEGFactory.createFromStream(org.apache.pdfbox.pdmodel.PDDocument, java.io.InputStream),
CCITTFactory.createFromFile(org.apache.pdfbox.pdmodel.PDDocument, java.io.File) or ImageIO.read(java.io.File) combined with
LosslessFactory.createFromImage(org.apache.pdfbox.pdmodel.PDDocument, java.awt.image.BufferedImage). (The later can also be used to create a
PDImageXObject from a BufferedImage).file - the image file.doc - the document that shall use this PDImageXObject.IOException - if there is an error when reading the file or creating the
PDImageXObject.IllegalArgumentException - if the image type is not supported.public static PDImageXObject createFromFileByContent(File file, PDDocument doc) throws IOException
JPEGFactory.createFromStream(org.apache.pdfbox.pdmodel.PDDocument, java.io.InputStream),
CCITTFactory.createFromFile(org.apache.pdfbox.pdmodel.PDDocument, java.io.File) or ImageIO.read(java.io.File) combined with
LosslessFactory.createFromImage(org.apache.pdfbox.pdmodel.PDDocument, java.awt.image.BufferedImage). (The later can also be used to create a
PDImageXObject from a BufferedImage).file - the image file.doc - the document that shall use this PDImageXObject.IOException - if there is an error when reading the file or creating the
PDImageXObject.IllegalArgumentException - if the image type is not supported.public PDMetadata getMetadata()
public void setMetadata(PDMetadata meta)
meta - the metadata associated with this objectpublic int getStructParent()
public void setStructParent(int key)
key - the new key for this XObjectpublic BufferedImage getImage() throws IOException
getImage in interface PDImageIOExceptionpublic BufferedImage getStencilImage(Paint paint) throws IOException
getStencilImage in interface PDImagepaint - the paint to fill the visible portions of the image withIOException - if the image cannot be readpublic BufferedImage getOpaqueImage() throws IOException
IOException - if the image cannot be readpublic PDImageXObject getMask() throws IOException
IOExceptionpublic COSArray getColorKeyMask()
public PDImageXObject getSoftMask() throws IOException
IOExceptionpublic int getBitsPerComponent()
PDImagegetBitsPerComponent in interface PDImagepublic void setBitsPerComponent(int bpc)
PDImagesetBitsPerComponent in interface PDImagebpc - The number of bits per component.public PDColorSpace getColorSpace() throws IOException
PDImagegetColorSpace in interface PDImageIOException - If there is an error getting the color space.public InputStream createInputStream() throws IOException
PDImagecreateInputStream in interface PDImageIOException - if the data could not be read.public InputStream createInputStream(List<String> stopFilters) throws IOException
PDImagecreateInputStream in interface PDImageIOException - if the data could not be read.public boolean isEmpty()
PDImagepublic void setColorSpace(PDColorSpace cs)
PDImagesetColorSpace in interface PDImagecs - The color space for this image.public int getHeight()
PDImagepublic void setHeight(int h)
PDImagepublic int getWidth()
PDImagepublic void setWidth(int w)
PDImagepublic boolean getInterpolate()
PDImagegetInterpolate in interface PDImagepublic void setInterpolate(boolean value)
PDImagesetInterpolate in interface PDImagepublic void setDecode(COSArray decode)
PDImagepublic COSArray getDecode()
PDImagepublic boolean isStencil()
PDImagepublic void setStencil(boolean isStencil)
PDImageImageMask entry in the image stream's dictionary.setStencil in interface PDImageisStencil - True to make the image a stencil.Copyright © 2002–2016 The Apache Software Foundation. All rights reserved.