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

public final Class PDInlineImage

extends Object
implements PDImage
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.graphics.image.PDImage, org.apache.pdfbox.pdmodel.common.COSObjectable
Imports
java.awt.Paint, .Rectangle, java.awt.image.BufferedImage, .WritableRaster, java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, java.util.Collections, .List, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSName, org.apache.pdfbox.filter.DecodeOptions, .DecodeResult, .Filter, .FilterFactory, org.apache.pdfbox.pdmodel.PDResources, org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace, .PDDeviceGray

An inline image object which uses a special syntax to express the data for a small image directly within the content stream.
Authors
Ben Litchfield, John Hewson

Field Summary

Modifier and TypeField and Description
private final byte[]
private final COSDictionary
private final byte[]
private final PDResources

Constructor Summary

AccessConstructor and Description
public
PDInlineImage(COSDictionary
the image parameters
parameters
,
byte[]
the image data
data
,
PDResources
the current resources
resources
)

Creates an inline image from the given parameters and data.

Method Summary

Modifier and TypeMethod and Description
private PDColorSpace
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.

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 PDColorSpace
public COSDictionary
getCOSObject()

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

Convert this image to a COS object.

public byte[]

Returns:

the inline image data
getData
()

Returns the inline image data.

public COSArray
public List<String>

Returns:

A (possibly empty) list of filters applied to this stream, never null.
getFilters
()

Returns A list of filters applied to this stream.

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 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 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 String

Returns:

The image suffix.
getSuffix
()

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

Returns 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.

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.

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

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.
colorSpace
)

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
setFilters(List<String>
the filters to apply to this stream.
filters
)

Sets which filters are applied to this stream.

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

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
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
setWidth(int
The width of the image.
width
)

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

Sets the width of the image.

private COSBase
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

decodedDataback to summary
private final byte[] decodedData
parametersback to summary
private final COSDictionary parameters
rawDataback to summary
private final byte[] rawData
resourcesback to summary
private final PDResources resources

Constructor Detail

PDInlineImageback to summary
public PDInlineImage(COSDictionary parameters, byte[] data, PDResources resources) throws IOException

Creates an inline image from the given parameters and data.

Parameters
parameters:COSDictionary

the image parameters

data:byte[]

the image data

resources:PDResources

the current resources

Exceptions
IOException:
if the stream cannot be decoded

Method Detail

createColorSpaceback to summary
private PDColorSpace createColorSpace(COSBase cs) throws IOException
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.
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
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.
getCOSObjectback to summary
public COSDictionary getCOSObject()

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

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

Convert this image to a COS object.

Returns:COSDictionary

The cos object that matches this image object.

Annotations
@Override
getDataback to summary
public byte[] getData()

Returns the inline image data.

Returns:byte[]

the inline image data

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
getFiltersback to summary
public List<String> getFilters()

Returns A list of filters applied to this stream.

Returns:List<String>

A (possibly empty) list of filters applied to this stream, never null.

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.

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
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
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.

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
getSuffixback to summary
public String getSuffix()

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

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

Returns:String

The image suffix.

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
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
setBitsPerComponentback to summary
public void setBitsPerComponent(int bitsPerComponent)

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

The number of bits per component.

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

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
colorSpace: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
setFiltersback to summary
public void setFilters(List<String> filters)

Sets which filters are applied to this stream.

Parameters
filters:List<String>

the filters to apply to this stream.

setHeightback to summary
public void setHeight(int height)

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
height: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
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
setWidthback to summary
public void setWidth(int width)

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

The width of the image.

Annotations
@Override
toLongNameback to summary
private COSBase toLongName(COSBase cs)