Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.graphics.image

public final Class PDImageXObject

extends PDXObject
implements PDImage
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.graphics.image.PDImage, org.apache.pdfbox.pdmodel.common.COSObjectable
Imports
java.awt.Graphics2D, .Paint, .Rectangle, .RenderingHints, java.awt.geom.AffineTransform, java.awt.image.AffineTransformOp, .BufferedImage, .DataBuffer, .ImagingOpException, .WritableRaster, java.io.BufferedInputStream, .ByteArrayInputStream, .File, .FileInputStream, .IOException, .InputStream, .OutputStream, java.lang.ref.SoftReference, java.util.List, javax.imageio.ImageIO, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSInputStream, .COSName, .COSObject, .COSStream, org.apache.pdfbox.filter.DecodeOptions, .DecodeResult, org.apache.pdfbox.io.IOUtils, org.apache.pdfbox.pdmodel.PDDocument, .PDResources, org.apache.pdfbox.pdmodel.common.PDMetadata, .PDStream, org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList, org.apache.pdfbox.pdmodel.graphics.PDXObject, org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace, .PDDeviceGray, org.apache.pdfbox.util.filetypedetector.FileType, .FileTypeDetector

An Image XObject.
Authors
John Hewson, Ben Litchfield

Field Summary

Modifier and TypeField and Description
private SoftReference<BufferedImage>
private int
private PDColorSpace
private boolean
private BufferedImage
private boolean
private static final Log
LOG

Log instance.

private final PDResources
resources

current resource dictionary (has color spaces)

Constructor Summary

AccessConstructor and Description
public
PDImageXObject(PDDocument
the current document
document
)

Creates an Image XObject in the given document.

public
PDImageXObject(PDDocument
the current document
document
,
InputStream
an encoded stream of image data
encodedStream
,
COSBase
the filter or a COSArray of filters
cosFilter
,
int
the image width
width
,
int
the image height
height
,
int
the bits per component
bitsPerComponent
,
PDColorSpace
the color space
initColorSpace
)

Creates an Image XObject in the given document using the given filtered stream.

public
PDImageXObject(PDStream
the XObject stream to read
stream
,
PDResources
the current resources
resources
)

Creates an Image XObject with the given stream as its contents and current color spaces.

Method Summary

Modifier and TypeMethod and Description
private BufferedImage

Returns:

an ARGB image (can be the altered original image)
applyMask
(BufferedImage
The image to apply the mask to as alpha channel.
image
,
BufferedImage
A mask image in 8 bit Gray. Even for a stencil mask image due to getOpaqueImage() and SampledImageReader's from1Bit() special handling of DeviceGray.
mask
,
boolean
interpolation flag of the mask image.
interpolateMask
,
boolean
true if a soft mask. If not stencil mask, then alpha will be inverted by this method.
isSoft
,
float[]
an optional RGB matte if a soft mask.
matte
)

private static int
clampColor(int color)

public static PDImageXObject

Returns:

a PDImageXObject.
createFromByteArray
(PDDocument
the document that shall use this PDImageXObject.
document
,
byte[]
bytes from an image file.
byteArray
,
String
name of image file for exception messages, can be null.
name
)

Create a PDImageXObject from bytes of an image file.

public static PDImageXObject

Returns:

a PDImageXObject.
createFromFile
(String
the image file path.
imagePath
,
PDDocument
the document that shall use this PDImageXObject.
doc
)

Create a PDImageXObject from an image file, see createFromFileByExtension(File, PDDocument) for more details.

public static PDImageXObject

Returns:

a PDImageXObject.
createFromFileByContent
(File
the image file.
file
,
PDDocument
the document that shall use this PDImageXObject.
doc
)

Create a PDImageXObject from an image file.

public static PDImageXObject

Returns:

a PDImageXObject.
createFromFileByExtension
(File
the image file.
file
,
PDDocument
the document that shall use this PDImageXObject.
doc
)

Create a PDImageXObject from an image file.

public InputStream
createInputStream()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.createInputStream.

Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.

public InputStream
createInputStream(DecodeOptions
Additional decoding options passed to the filters used
options
)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.createInputStream.

Returns an InputStream, passing additional options to each filter.

public InputStream
createInputStream(List<String>
A list of filters to stop decoding at.
stopFilters
)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.createInputStream.

Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.

private static COSStream
createRawStream(PDDocument document, InputStream rawInput)

Creates a COS stream from raw (encoded) data.

public static PDImageXObject

Returns:

an XObject
createThumbnail
(COSStream
the COS stream
cosStream
)

Creates a thumbnail Image XObject from the given COSBase and name.

private float[]

Returns:

the matte color.
extractMatte
(PDImageXObject softMask)

Extract the matte color from a softmask.

public int
getBitsPerComponent()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getBitsPerComponent.

Returns bits per component of this image, or -1 if one has not been set.

public COSArray

Returns:

Mask Image XObject
getColorKeyMask
()

Returns the color key mask array associated with this image, or null if there is none.

public PDColorSpace
public COSArray
public int
getHeight()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getHeight.

Returns height of this image, or -1 if one has not been set.

public BufferedImage
getImage()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getImage.

Returns the content of this image as an AWT buffered image with an (A)RGB color space.

public BufferedImage
getImage(Rectangle
The region of the source image to get, or null if the entire image is needed. The actual region will be clipped to the dimensions of the source image.
region
,
int
The amount of rows and columns to advance for every output pixel, a value of 1 meaning every pixel will be read
subsampling
)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getImage.

Returns the content of this image as an AWT buffered image with an (A)RGB colored space.

public boolean
getInterpolate()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getInterpolate.

Returns true if the image should be interpolated when rendered.

public PDImageXObject

Returns:

Mask Image XObject
getMask
()

Returns the Mask Image XObject associated with this image, or null if there is none.

public PDMetadata

Returns:

the metadata associated with this object.
getMetadata
()

Returns the metadata associated with this XObject, or null if there is none.

public BufferedImage

Returns:

the image without any masks applied
getOpaqueImage
()

Returns an RGB buffered image containing the opaque image stream without any masks applied.

public BufferedImage

Returns:

the image without any masks applied
getOpaqueImage
(Rectangle
The region of the source image to get, or null if the entire image is needed. The actual region will be clipped to the dimensions of the source image.
region
,
int
The amount of rows and columns to advance for every output pixel, a value of 1 meaning every pixel will be read. It must not be larger than the image width or height.
subsampling
)

Returns an RGB buffered image containing the opaque image stream without any masks applied.

public PDPropertyList

Returns:

The optional content group or optional content membership dictionary or null if there is none.
getOptionalContent
()

This will get the optional content group or optional content membership dictionary.

public BufferedImage
getRawImage()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getRawImage.

Try to get the raw image as AWT buffered image with it's original colorspace.

public WritableRaster
getRawRaster()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getRawRaster.

Return the image data as WritableRaster.

public PDImageXObject

Returns:

the SMask Image XObject, or null.
getSoftMask
()

Returns the Soft Mask Image XObject associated with this image, or null if there is none.

public BufferedImage
getStencilImage(Paint
the paint to fill the visible portions of the image with
paint
)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getStencilImage.

Returns an ARGB image filled with the given paint and using this image as a mask.

public int

Returns:

this object's key the structural parent tree or -1 if there isn't any.
getStructParent
()

Returns the key of this XObject in the structural parent tree.

public String

Returns:

The image suffix or null if not available.
getSuffix
()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getSuffix.

This will get the suffix for this image type, e.g. jpg/png.

public int
getWidth()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getWidth.

Returns the width of this image, or -1 if one has not been set.

private void
public boolean
isEmpty()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.isEmpty.

Returns true if the image has no data.

public boolean
isStencil()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.isStencil.

Returns true if the image is a stencil mask.

private static BufferedImage
scaleImage(BufferedImage image, int width, int height, int type, boolean interpolate)

High-quality image scaling.

public void
setBitsPerComponent(int
The number of bits per component.
bpc
)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setBitsPerComponent.

Set the number of bits per component.

public void
setColorSpace(PDColorSpace
The color space for this image.
cs
)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setColorSpace.

Sets the color space for this image.

public void
setDecode(COSArray
the new decode array.
decode
)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setDecode.

Sets the decode array.

public void
setHeight(int
The height of the image.
h
)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setHeight.

Sets the height of the image.

public void
setInterpolate(boolean
true for high-quality image scaling
value
)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setInterpolate.

Sets the Interpolate flag, true for high-quality image scaling.

public void
setMetadata(PDMetadata
the metadata associated with this object
meta
)

Sets the metadata associated with this XObject, or null if there is none.

public void
setOptionalContent(PDPropertyList
The optional content group or optional content membership dictionary.
oc
)

Sets the optional content group or optional content membership dictionary.

public void
setStencil(boolean
True to make the image a stencil.
isStencil
)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setStencil.

Sets whether or not the image is a stencil.

public void
setStructParent(int
the new key for this XObject
key
)

Sets the key of this XObject in the structural parent tree.

public void
setWidth(int
The width of the image.
w
)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setWidth.

Sets the width of the image.

Inherited from org.apache.pdfbox.pdmodel.graphics.PDXObject:
createXObjectgetCOSObjectgetStream

Field Detail

cachedImageback to summary
private SoftReference<BufferedImage> cachedImage
cachedImageSubsamplingback to summary
private int cachedImageSubsampling
colorSpaceback to summary
private PDColorSpace colorSpace
hasJPXFilterback to summary
private boolean hasJPXFilter
jpxSMaskback to summary
private BufferedImage jpxSMask
jpxValuesInitializedback to summary
private boolean jpxValuesInitialized
LOGback to summary
private static final Log LOG

Log instance.

resourcesback to summary
private final PDResources resources

current resource dictionary (has color spaces)

Constructor Detail

PDImageXObjectback to summary
public PDImageXObject(PDDocument document) throws IOException

Creates an Image XObject in the given document. This constructor is for internal PDFBox use and is not for PDF generation. Users who want to create images should look at createFromFileByExtension(File, PDDocument).

Parameters
document:PDDocument

the current document

Exceptions
IOException:
if there is an error creating the XObject.
PDImageXObjectback to summary
public PDImageXObject(PDDocument document, InputStream encodedStream, COSBase cosFilter, int width, int height, int bitsPerComponent, PDColorSpace initColorSpace) throws IOException

Creates an Image XObject in the given document using the given filtered stream. This constructor is for internal PDFBox use and is not for PDF generation. Users who want to create images should look at createFromFileByExtension(File, PDDocument).

Parameters
document:PDDocument

the current document

encodedStream:InputStream

an encoded stream of image data

cosFilter:COSBase

the filter or a COSArray of filters

width:int

the image width

height:int

the image height

bitsPerComponent:int

the bits per component

initColorSpace:PDColorSpace

the color space

Exceptions
IOException:
if there is an error creating the XObject.
PDImageXObjectback to summary
public PDImageXObject(PDStream stream, PDResources resources) throws IOException

Creates an Image XObject with the given stream as its contents and current color spaces. This constructor is for internal PDFBox use and is not for PDF generation. Users who want to create images should look at createFromFileByExtension(File, PDDocument).

Parameters
stream:PDStream

the XObject stream to read

resources:PDResources

the current resources

Exceptions
IOException:
if there is an error creating the XObject.

Method Detail

applyMaskback to summary
private BufferedImage applyMask(BufferedImage image, BufferedImage mask, boolean interpolateMask, boolean isSoft, float[] matte)
Parameters
image:BufferedImage

The image to apply the mask to as alpha channel.

mask:BufferedImage

A mask image in 8 bit Gray. Even for a stencil mask image due to getOpaqueImage() and SampledImageReader's from1Bit() special handling of DeviceGray.

interpolateMask:boolean

interpolation flag of the mask image.

isSoft:boolean

true if a soft mask. If not stencil mask, then alpha will be inverted by this method.

matte:float[]

an optional RGB matte if a soft mask.

Returns:BufferedImage

an ARGB image (can be the altered original image)

clampColorback to summary
private static int clampColor(int color)
createFromByteArrayback to summary
public static PDImageXObject createFromByteArray(PDDocument document, byte[] byteArray, String name) throws IOException

Create a PDImageXObject from bytes of an image file. The file format is determined by the file content. The following file types are supported: JPG, JPEG, TIF, TIFF, GIF, BMP and PNG. This is a convenience method that calls JPEGFactory#createFromByteArray, CCITTFactory#createFromFile or ImageIO#read combined with LosslessFactory#createFromImage. (The later can also be used to create a PDImageXObject from a BufferedImage). Starting with 2.0.18, this call will create an image directly from a PNG file without decoding it (when possible), which is faster. However the result size depends on the compression skill of the software that created the PNG file. If file size or bandwidth are important to you or to your clients, then create your PNG files with a tool that has implemented the Zopfli algorithm, or use the two-step process mentioned above.

Parameters
document:PDDocument

the document that shall use this PDImageXObject.

byteArray:byte[]

bytes from an image file.

name:String

name of image file for exception messages, can be null.

Returns:PDImageXObject

a PDImageXObject.

Exceptions
IOException:
if there is an error when reading the file or creating the PDImageXObject.
IllegalArgumentException:
if the image type is not supported.
createFromFileback to summary
public static PDImageXObject createFromFile(String imagePath, PDDocument doc) throws IOException

Create a PDImageXObject from an image file, see createFromFileByExtension(File, PDDocument) for more details.

Parameters
imagePath:String

the image file path.

doc:PDDocument

the document that shall use this PDImageXObject.

Returns:PDImageXObject

a PDImageXObject.

Exceptions
IOException:
if there is an error when reading the file or creating the PDImageXObject, or if the image type is not supported.
createFromFileByContentback to summary
public static PDImageXObject createFromFileByContent(File file, PDDocument doc) throws IOException

Create a PDImageXObject from an image file. The file format is determined by the file content. The following file types are supported: JPG, JPEG, TIF, TIFF, GIF, BMP and PNG. This is a convenience method that calls JPEGFactory#createFromStream, CCITTFactory#createFromFile or ImageIO#read combined with LosslessFactory#createFromImage. (The later can also be used to create a PDImageXObject from a BufferedImage). Starting with 2.0.18, this call will create an image directly from a PNG file without decoding it (when possible), which is faster. However the result size depends on the compression skill of the software that created the PNG file. If file size or bandwidth are important to you or to your clients, then create your PNG files with a tool that has implemented the Zopfli algorithm, or use the two-step process mentioned above.

Parameters
file:File

the image file.

doc:PDDocument

the document that shall use this PDImageXObject.

Returns:PDImageXObject

a PDImageXObject.

Exceptions
IOException:
if there is an error when reading the file or creating the PDImageXObject.
IllegalArgumentException:
if the image type is not supported.
createFromFileByExtensionback to summary
public static PDImageXObject createFromFileByExtension(File file, PDDocument doc) throws IOException

Create a PDImageXObject from an image file. The file format is determined by the file name suffix. The following suffixes are supported: JPG, JPEG, TIF, TIFF, GIF, BMP and PNG. This is a convenience method that calls JPEGFactory#createFromStream, CCITTFactory#createFromFile or ImageIO#read combined with LosslessFactory#createFromImage. (The later can also be used to create a PDImageXObject from a BufferedImage). Starting with 2.0.18, this call will create an image directly from a PNG file without decoding it (when possible), which is faster. However the result size depends on the compression skill of the software that created the PNG file. If file size or bandwidth are important to you or to your clients, then create your PNG files with a tool that has implemented the Zopfli algorithm, or use the two-step process mentioned above.

Parameters
file:File

the image file.

doc:PDDocument

the document that shall use this PDImageXObject.

Returns:PDImageXObject

a PDImageXObject.

Exceptions
IOException:
if there is an error when reading the file or creating the PDImageXObject.
IllegalArgumentException:
if the image type is not supported.
createInputStreamback to summary
public InputStream createInputStream() throws IOException

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.createInputStream.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.createInputStream.

Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject.

Returns:InputStream

Decoded stream

Annotations
@Override
Exceptions
IOException:
if the data could not be read.
createInputStreamback to summary
public InputStream createInputStream(DecodeOptions options) throws IOException

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.createInputStream.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.createInputStream.

Returns an InputStream, passing additional options to each filter. As a side effect, the filterSubsampled flag is set in DecodeOptions.

Parameters
options:DecodeOptions

Additional decoding options passed to the filters used

Returns:InputStream

Decoded stream

Annotations
@Override
Exceptions
IOException:
if the data could not be read
createInputStreamback to summary
public InputStream createInputStream(List<String> stopFilters) throws IOException

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.createInputStream.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.createInputStream.

Returns an InputStream containing the image data, irrespective of whether this is an inline image or an image XObject. The given filters will not be decoded.

Parameters
stopFilters:List<String>

A list of filters to stop decoding at.

Returns:InputStream

Decoded stream

Annotations
@Override
Exceptions
IOException:
if the data could not be read.
createRawStreamback to summary
private static COSStream createRawStream(PDDocument document, InputStream rawInput) throws IOException

Creates a COS stream from raw (encoded) data.

createThumbnailback to summary
public static PDImageXObject createThumbnail(COSStream cosStream) throws IOException

Creates a thumbnail Image XObject from the given COSBase and name.

Parameters
cosStream:COSStream

the COS stream

Returns:PDImageXObject

an XObject

Exceptions
IOException:
if there is an error creating the XObject.
extractMatteback to summary
private float[] extractMatte(PDImageXObject softMask) throws IOException

Extract the matte color from a softmask.

Returns:float[]

the matte color.

Exceptions
IOException:
if the color conversion fails.
getBitsPerComponentback to summary
public int getBitsPerComponent()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getBitsPerComponent.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.getBitsPerComponent.

Returns bits per component of this image, or -1 if one has not been set.

Returns:int

bits per component of this image or -1

Annotations
@Override
getColorKeyMaskback to summary
public COSArray getColorKeyMask()

Returns the color key mask array associated with this image, or null if there is none.

Returns:COSArray

Mask Image XObject

getColorSpaceback to summary
public PDColorSpace getColorSpace() throws IOException

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getColorSpace.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.getColorSpace.

Returns the image's color space.

Returns:PDColorSpace

the image's color space

Annotations
@Override
Exceptions
IOException:
If there is an error getting the color space.
getDecodeback to summary
public COSArray getDecode()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getDecode.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.getDecode.

Returns the decode array.

Returns:COSArray

the decode array

Annotations
@Override
getHeightback to summary
public int getHeight()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getHeight.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.getHeight.

Returns height of this image, or -1 if one has not been set.

Returns:int

height of this image or -1

Annotations
@Override
getImageback to summary
public BufferedImage getImage() throws IOException

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getImage.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.getImage.

Returns the content of this image as an AWT buffered image with an (A)RGB color space. The size of the returned image is the larger of the size of the image itself or its mask. The returned images are cached via a SoftReference.

Returns:BufferedImage

content of this image as a buffered image.

Annotations
@Override
Exceptions
IOException:
if the buffered image could not be created
getImageback to summary
public BufferedImage getImage(Rectangle region, int subsampling) throws IOException

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getImage.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.getImage.

Returns the content of this image as an AWT buffered image with an (A)RGB colored space. Only the subregion specified is rendered, and is subsampled by advancing the specified amount of rows and columns in the source image for every resulting pixel. Note that unlike the unparameterized version, this method does not cache the resulting image.

Parameters
region:Rectangle

The region of the source image to get, or null if the entire image is needed. The actual region will be clipped to the dimensions of the source image.

subsampling:int

The amount of rows and columns to advance for every output pixel, a value of 1 meaning every pixel will be read

Returns:BufferedImage

subsampled content of the requested subregion as a buffered image.

Annotations
@Override
Exceptions
IOException:
if the buffered image could not be created
getInterpolateback to summary
public boolean getInterpolate()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getInterpolate.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.getInterpolate.

Returns true if the image should be interpolated when rendered.

Returns:boolean

true if the image should be interpolated when rendered

Annotations
@Override
getMaskback to summary
public PDImageXObject getMask() throws IOException

Returns the Mask Image XObject associated with this image, or null if there is none.

Returns:PDImageXObject

Mask Image XObject

Exceptions
IOException:
if the mask data could not be read
getMetadataback to summary
public PDMetadata getMetadata()

Returns the metadata associated with this XObject, or null if there is none.

Returns:PDMetadata

the metadata associated with this object.

getOpaqueImageback to summary
public BufferedImage getOpaqueImage() throws IOException

Returns an RGB buffered image containing the opaque image stream without any masks applied. If this Image XObject is a mask then the buffered image will contain the raw mask.

Returns:BufferedImage

the image without any masks applied

Exceptions
IOException:
if the image cannot be read
getOpaqueImageback to summary
public BufferedImage getOpaqueImage(Rectangle region, int subsampling) throws IOException

Returns an RGB buffered image containing the opaque image stream without any masks applied. If this Image XObject is a mask then the buffered image will contain the raw mask.

Parameters
region:Rectangle

The region of the source image to get, or null if the entire image is needed. The actual region will be clipped to the dimensions of the source image.

subsampling:int

The amount of rows and columns to advance for every output pixel, a value of 1 meaning every pixel will be read. It must not be larger than the image width or height.

Returns:BufferedImage

the image without any masks applied

Exceptions
IOException:
if the image cannot be read
getOptionalContentback to summary
public PDPropertyList getOptionalContent()

This will get the optional content group or optional content membership dictionary.

Returns:PDPropertyList

The optional content group or optional content membership dictionary or null if there is none.

getRawImageback to summary
public BufferedImage getRawImage() throws IOException

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getRawImage.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.getRawImage.

Try to get the raw image as AWT buffered image with it's original colorspace. No color conversion is performed. You could use the returned BufferedImage for draw operations. But this would be very slow as the color conversion would happen on demand. You rather should use getImage() for that. This method returns null if it is not possible to map the underlying colorspace into a java.awt.ColorSpace. Use this method if you want to extract the image without loosing any color information, as no color conversion will be performed. You can alwoys use getRawRaster(), if you want to access the raw data even if no matching java.awt.ColorSpace exists

Returns:BufferedImage

the raw image with a java.awt.ColorSpace or null

Annotations
@Override
Exceptions
IOException:
if the raw image could not be created
getRawRasterback to summary
public WritableRaster getRawRaster() throws IOException

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getRawRaster.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.getRawRaster.

Return the image data as WritableRaster. You should consult the PDColorSpace returned by getColorSpace() to know how to interpret the data in this WritableRaster. Use this if e.g. want access to the raw color information of a org.apache.pdfbox.pdmodel.graphics.color.PDDeviceN image.

Returns:WritableRaster

the raw writable raster for this image

Annotations
@Override
Exceptions
IOException:
if the buffered raw writable raster could not be created
getSoftMaskback to summary
public PDImageXObject getSoftMask() throws IOException

Returns the Soft Mask Image XObject associated with this image, or null if there is none.

Returns:PDImageXObject

the SMask Image XObject, or null.

Exceptions
IOException:
if the soft mask data could not be read
getStencilImageback to summary
public BufferedImage getStencilImage(Paint paint) throws IOException

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getStencilImage.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.getStencilImage.

Returns an ARGB image filled with the given paint and using this image as a mask. The returned images are not cached.

Parameters
paint:Paint

the paint to fill the visible portions of the image with

Returns:BufferedImage

a masked image filled with the given paint

Annotations
@Override
Exceptions
IOException:
if the image cannot be read
getStructParentback to summary
public int getStructParent()

Returns the key of this XObject in the structural parent tree.

Returns:int

this object's key the structural parent tree or -1 if there isn't any.

getSuffixback to summary
public String getSuffix()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getSuffix.

This will get the suffix for this image type, e.g. jpg/png.

Returns:String

The image suffix or null if not available.

Annotations
@Override
getWidthback to summary
public int getWidth()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.getWidth.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.getWidth.

Returns the width of this image, or -1 if one has not been set.

Returns:int

width of this image or -1

Annotations
@Override
initJPXValuesback to summary
private void initJPXValues()
isEmptyback to summary
public boolean isEmpty()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.isEmpty.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.isEmpty.

Returns true if the image has no data.

Returns:boolean

true if the image has no data

Annotations
@Override
isStencilback to summary
public boolean isStencil()

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.isStencil.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.isStencil.

Returns true if the image is a stencil mask.

Returns:boolean

true if the image is a stencil mask

Annotations
@Override
scaleImageback to summary
private static BufferedImage scaleImage(BufferedImage image, int width, int height, int type, boolean interpolate)

High-quality image scaling.

setBitsPerComponentback to summary
public void setBitsPerComponent(int bpc)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setBitsPerComponent.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.setBitsPerComponent.

Set the number of bits per component.

Parameters
bpc:int

The number of bits per component.

Annotations
@Override
setColorSpaceback to summary
public void setColorSpace(PDColorSpace cs)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setColorSpace.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.setColorSpace.

Sets the color space for this image.

Parameters
cs:PDColorSpace

The color space for this image.

Annotations
@Override
setDecodeback to summary
public void setDecode(COSArray decode)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setDecode.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.setDecode.

Sets the decode array.

Parameters
decode:COSArray

the new decode array.

Annotations
@Override
setHeightback to summary
public void setHeight(int h)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setHeight.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.setHeight.

Sets the height of the image. This is for internal PDFBox usage and not to set the size of the image on the page.

Parameters
h:int

The height of the image.

Annotations
@Override
setInterpolateback to summary
public void setInterpolate(boolean value)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setInterpolate.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.setInterpolate.

Sets the Interpolate flag, true for high-quality image scaling.

Parameters
value:boolean

true for high-quality image scaling

Annotations
@Override
setMetadataback to summary
public void setMetadata(PDMetadata meta)

Sets the metadata associated with this XObject, or null if there is none.

Parameters
meta:PDMetadata

the metadata associated with this object

setOptionalContentback to summary
public void setOptionalContent(PDPropertyList oc)

Sets the optional content group or optional content membership dictionary.

Parameters
oc:PDPropertyList

The optional content group or optional content membership dictionary.

setStencilback to summary
public void setStencil(boolean isStencil)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setStencil.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.setStencil.

Sets whether or not the image is a stencil. This corresponds to the ImageMask entry in the image stream's dictionary.

Parameters
isStencil:boolean

True to make the image a stencil.

Annotations
@Override
setStructParentback to summary
public void setStructParent(int key)

Sets the key of this XObject in the structural parent tree.

Parameters
key:int

the new key for this XObject

setWidthback to summary
public void setWidth(int w)

Implements org.apache.pdfbox.pdmodel.graphics.image.PDImage.setWidth.

Doc from org.apache.pdfbox.pdmodel.graphics.image.PDImage.setWidth.

Sets the width of the image. This is for internal PDFBox usage and not to set the size of the image on the page.

Parameters
w:int

The width of the image.

Annotations
@Override