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

public Interface PDImage

extends COSObjectable
Known Direct Implementers
org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject, org.apache.pdfbox.pdmodel.graphics.image.PDInlineImage
Imports
java.awt.Paint, .Rectangle, java.awt.image.BufferedImage, .WritableRaster, java.io.IOException, .InputStream, java.util.List, org.apache.pdfbox.cos.COSArray, .COSDictionary, org.apache.pdfbox.filter.DecodeOptions, org.apache.pdfbox.pdmodel.common.COSObjectable, org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace

An image in a PDF document.
Author
John Hewson

Method Summary

Modifier and TypeMethod and Description
public InputStream

Returns:

Decoded stream
createInputStream
()

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

public InputStream

Returns:

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

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

public InputStream

Returns:

Decoded stream
createInputStream
(DecodeOptions
Additional decoding options passed to the filters used
options
)

Returns an InputStream, passing additional options to each filter.

public int

Returns:

bits per component of this image or -1
getBitsPerComponent
()

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

public PDColorSpace

Returns:

the image's color space
getColorSpace
()

Returns the image's color space.

public COSDictionary

Returns:

The cos object that matches this image object.
getCOSObject
()

Redeclares org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Convert this image to a COS object.

public COSArray

Returns:

the decode array
getDecode
()

Returns the decode array.

public int

Returns:

height of this image or -1
getHeight
()

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

public BufferedImage

Returns:

content of this image as a buffered image.
getImage
()

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

public BufferedImage

Returns:

subsampled content of the requested subregion as a buffered image.
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
)

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

public boolean

Returns:

true if the image should be interpolated when rendered
getInterpolate
()

Returns true if the image should be interpolated when rendered.

public BufferedImage

Returns:

the raw image with a java.awt.ColorSpace or null
getRawImage
()

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

public WritableRaster

Returns:

the raw writable raster for this image
getRawRaster
()

Return the image data as WritableRaster.

public BufferedImage

Returns:

a masked image filled with the given paint
getStencilImage
(Paint
the paint to fill the visible portions of the image with
paint
)

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

public String

Returns:

the suffix for this image type
getSuffix
()

Returns the suffix for this image type, e.g. "jpg"

public int

Returns:

width of this image or -1
getWidth
()

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

public boolean

Returns:

true if the image has no data
isEmpty
()

Returns true if the image has no data.

public boolean

Returns:

true if the image is a stencil mask
isStencil
()

Returns true if the image is a stencil mask.

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

Set the number of bits per component.

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

Sets the color space for this image.

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

Sets the decode array.

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

Sets the height of the image.

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

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

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

Sets whether or not the image is a stencil.

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

Sets the width of the image.

Method Detail

createInputStreamback to summary
public InputStream createInputStream() throws IOException

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

Returns:InputStream

Decoded stream

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

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

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

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

Exceptions
IOException:
if the data could not be read
getBitsPerComponentback to summary
public int 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

getColorSpaceback to summary
public PDColorSpace getColorSpace() throws IOException

Returns the image's color space.

Returns:PDColorSpace

the image's color space

Exceptions
IOException:
If there is an error getting the color space.
getCOSObjectback to summary
public COSDictionary getCOSObject()

Redeclares org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Convert this image to a COS object.

Returns:COSDictionary

The cos object that matches this image object.

Annotations
@Override
getDecodeback to summary
public COSArray getDecode()

Returns the decode array.

Returns:COSArray

the decode array

getHeightback to summary
public int getHeight()

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

Returns:int

height of this image or -1

getImageback to summary
public BufferedImage getImage() throws IOException

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.

Returns:BufferedImage

content of this image as a buffered image.

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

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.

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

Returns true if the image should be interpolated when rendered.

Returns:boolean

true if the image should be interpolated when rendered

getRawImageback to summary
public BufferedImage getRawImage() throws IOException

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

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

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

Exceptions
IOException:
if the buffered raw writable raster could not be created
getStencilImageback to summary
public BufferedImage getStencilImage(Paint paint) throws IOException

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

Parameters
paint:Paint

the paint to fill the visible portions of the image with

Returns:BufferedImage

a masked image filled with the given paint

Exceptions
IOException:
if the image cannot be read
IllegalStateException:
if the image is not a stencil.
getSuffixback to summary
public String getSuffix()

Returns the suffix for this image type, e.g. "jpg"

Returns:String

the suffix for this image type

getWidthback to summary
public int getWidth()

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

Returns:int

width of this image or -1

isEmptyback to summary
public boolean isEmpty()

Returns true if the image has no data.

Returns:boolean

true if the image has no data

isStencilback to summary
public boolean isStencil()

Returns true if the image is a stencil mask.

Returns:boolean

true if the image is a stencil mask

setBitsPerComponentback to summary
public void setBitsPerComponent(int bitsPerComponent)

Set the number of bits per component.

Parameters
bitsPerComponent:int

The number of bits per component.

setColorSpaceback to summary
public void setColorSpace(PDColorSpace colorSpace)

Sets the color space for this image.

Parameters
colorSpace:PDColorSpace

The color space for this image.

setDecodeback to summary
public void setDecode(COSArray decode)

Sets the decode array.

Parameters
decode:COSArray

the new decode array.

setHeightback to summary
public void setHeight(int height)

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
height:int

The height of the image.

setInterpolateback to summary
public void setInterpolate(boolean value)

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

Parameters
value:boolean

true for high-quality image scaling

setStencilback to summary
public void setStencil(boolean isStencil)

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.

setWidthback to summary
public void setWidth(int width)

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
width:int

The width of the image.