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

public final Class PDResources

extends Object
implements COSObjectable
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.common.COSObjectable
Imports
java.io.IOException, java.lang.ref.SoftReference, java.util.Collections, .HashMap, .Map, org.apache.pdfbox.cos.COSBase, .COSDictionary, .COSName, .COSObject, .COSStream, org.apache.pdfbox.pdmodel.common.COSObjectable, org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList, org.apache.pdfbox.pdmodel.font.PDFont, .PDFontFactory, org.apache.pdfbox.pdmodel.graphics.color.PDPattern, .PDColorSpace, org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject, org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentGroup, org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState, org.apache.pdfbox.pdmodel.graphics.pattern.PDAbstractPattern, org.apache.pdfbox.pdmodel.graphics.shading.PDShading, org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject, org.apache.pdfbox.pdmodel.graphics.PDXObject

A set of resources available at the page/pages/stream level.
Authors
Ben Litchfield, John Hewson

Field Summary

Modifier and TypeField and Description
private final ResourceCache
private final Map<COSName, SoftReference<PDFont>>
private final COSDictionary

Constructor Summary

AccessConstructor and Description
public
PDResources()

Constructor for embedding.

public
PDResources(COSDictionary
The cos dictionary for this resource.
resourceDictionary
)

Constructor for reading.

public
PDResources(COSDictionary
The cos dictionary for this resource.
resourceDictionary
,
ResourceCache
The document's resource cache, may be null.
resourceCache
)

Constructor for reading.

public
PDResources(COSDictionary
The cos dictionary for this resource.
resourceDictionary
,
ResourceCache
The document's resource cache, may be null.
resourceCache
,
Map<COSName, SoftReference<PDFont>>
The document's direct font cache. Must be mutable
directFontCache
)

Constructor for reading.

Method Summary

Modifier and TypeMethod and Description
public COSName

Returns:

the name of the resource in the resources dictionary
add
(PDFont
the font to add
font
)

Adds the given font to the resources of the current page and returns the name for the new resources.

public COSName

Returns:

the name of the resource in the resources dictionary
add
(PDColorSpace
the color space to add
colorSpace
)

Adds the given color space to the resources of the current page and returns the name for the new resources.

public COSName

Returns:

the name of the resource in the resources dictionary
add
(PDExtendedGraphicsState
the extended graphics state to add
extGState
)

Adds the given extended graphics state to the resources of the current page and returns the name for the new resources.

public COSName

Returns:

the name of the resource in the resources dictionary
add
(PDShading
the shading to add
shading
)

Adds the given shading to the resources of the current page and returns the name for the new resources.

public COSName

Returns:

the name of the resource in the resources dictionary
add
(PDAbstractPattern
the pattern to add
pattern
)

Adds the given pattern to the resources of the current page and returns the name for the new resources.

public COSName

Returns:

the name of the resource in the resources dictionary
add
(PDPropertyList
the property list to add
properties
)

Adds the given property list to the resources of the current page and returns the name for the new resources.

public COSName

Returns:

the name of the resource in the resources dictionary
add
(PDImageXObject
the image to add
image
)

Adds the given image to the resources of the current page and returns the name for the new resources.

public COSName

Returns:

the name of the resource in the resources dictionary
add
(PDFormXObject
the form to add
form
)

Adds the given form to the resources of the current page and returns the name for the new resources.

public COSName

Returns:

the name of the resource in the resources dictionary
add
(PDXObject
the XObject to add
xobject
,
String
the prefix to be used when creating the resource name
prefix
)

Adds the given XObject to the resources of the current page and returns the name for the new resources.

private COSName
add(COSName kind, String prefix, COSObjectable object)

Adds the given resource if it does not already exist.

private COSName
createKey(COSName kind, String prefix)

Returns a unique key for a new resource.

private COSBase
get(COSName kind, COSName name)

Returns the resource with the given name and kind, or null.

public PDColorSpace

Returns:

a new color space.
getColorSpace
(COSName
Name of the color space resource.
name
)

Returns the color space resource with the given name, or null if none exists.

public PDColorSpace

Returns:

a new color space.
getColorSpace
(COSName
Name of the color space resource.
name
,
boolean
if current color space was used by a default color space. This parameter is to
wasDefault
)

Returns the color space resource with the given name, or null if none exists.

public Iterable<COSName>

Returns:

an iterable containing all names of available colorspaces
getColorSpaceNames
()

Returns the names of the color space resources, if any.

public COSDictionary
getCOSObject()

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

Returns the underlying dictionary.

public PDExtendedGraphicsState

Returns:

the extended graphics state with the given name or null
getExtGState
(COSName
Name of the graphics state resource.
name
)

Returns the extended graphics state resource with the given name, or null if none exists.

public Iterable<COSName>

Returns:

an iterable containing all names of available extended graphics states
getExtGStateNames
()

Returns the names of the extended graphics state resources, if any.

public PDFont

Returns:

the font with the given name or null
getFont
(COSName
Name of the font resource.
name
)

Returns the font resource with the given name, or null if none exists.

public Iterable<COSName>

Returns:

an iterable containing all names of available fonts
getFontNames
()

Returns the names of the font resources, if any.

private COSObject
getIndirect(COSName kind, COSName name)

Returns the resource with the given name and kind as an indirect object, or null.

private Iterable<COSName>
getNames(COSName kind)

Returns the resource names of the given kind.

public PDAbstractPattern

Returns:

the pattern with the given name or null
getPattern
(COSName
Name of the pattern resource.
name
)

Returns the pattern resource with the given name, or null if none exists.

public Iterable<COSName>

Returns:

an iterable containing all names of available patterns
getPatternNames
()

Returns the names of the pattern resources, if any.

public PDPropertyList

Returns:

the property list with the given name or null
getProperties
(COSName
Name of the property list resource.
name
)

Returns the property list resource with the given name, or null if none exists.

public Iterable<COSName>

Returns:

an iterable containing all names of available property lists
getPropertiesNames
()

Returns the names of the property list resources, if any.

public ResourceCache

Returns:

the resource cache associated with the resources, or null
getResourceCache
()

Returns the resource cache associated with the Resources, or null if there is none.

public PDShading

Returns:

the shading state with the given name or null
getShading
(COSName
Name of the shading resource.
name
)

Returns the shading resource with the given name, or null if none exists.

public Iterable<COSName>

Returns:

an iterable containing all names of available shadings
getShadingNames
()

Returns the names of the shading resources, if any.

public PDXObject

Returns:

the XObject with the given name or null
getXObject
(COSName
Name of the XObject resource.
name
)

Returns the XObject resource with the given name, or null if none exists.

public Iterable<COSName>

Returns:

an iterable containing all names of available xobjects
getXObjectNames
()

Returns the names of the XObject resources, if any.

public boolean

Returns:

true if the given color space name exists in these resources, otherwise false
hasColorSpace
(COSName
Name of the color space resource.
name
)

Returns true if the given color space name exists in these resources.

private boolean
public boolean

Returns:

true if it is an image XObject, false if not.
isImageXObject
(COSName
Name of the XObject resource.
name
)

Tells whether the XObject resource with the given name is an image.

private void
put(COSName kind, COSName name, COSObjectable object)

Sets the value of a given named resource.

public void
put(COSName
the name of the resource
name
,
PDFont
the font to be added
font
)

Sets the font resource with the given name.

public void
put(COSName
the name of the resource
name
,
PDColorSpace
the color space to be added
colorSpace
)

Sets the color space resource with the given name.

public void
put(COSName
the name of the resource
name
,
PDExtendedGraphicsState
the extended graphics state to be added
extGState
)

Sets the extended graphics state resource with the given name.

public void
put(COSName
the name of the resource
name
,
PDShading
the shading to be added
shading
)

Sets the shading resource with the given name.

public void
put(COSName
the name of the resource
name
,
PDAbstractPattern
the pattern to be added
pattern
)

Sets the pattern resource with the given name.

public void
put(COSName
the name of the resource
name
,
PDPropertyList
the property list to be added
properties
)

Sets the property list resource with the given name.

public void
put(COSName
the name of the resource
name
,
PDXObject
the XObject to be added
xobject
)

Sets the XObject resource with the given name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private final ResourceCache cache
directFontCacheback to summary
private final Map<COSName, SoftReference<PDFont>> directFontCache
resourcesback to summary
private final COSDictionary resources

Constructor Detail

PDResourcesback to summary
public PDResources()

Constructor for embedding.

PDResourcesback to summary
public PDResources(COSDictionary resourceDictionary)

Constructor for reading.

Parameters
resourceDictionary:COSDictionary

The cos dictionary for this resource.

PDResourcesback to summary
public PDResources(COSDictionary resourceDictionary, ResourceCache resourceCache)

Constructor for reading.

Parameters
resourceDictionary:COSDictionary

The cos dictionary for this resource.

resourceCache:ResourceCache

The document's resource cache, may be null.

PDResourcesback to summary
public PDResources(COSDictionary resourceDictionary, ResourceCache resourceCache, Map<COSName, SoftReference<PDFont>> directFontCache)

Constructor for reading.

Parameters
resourceDictionary:COSDictionary

The cos dictionary for this resource.

resourceCache:ResourceCache

The document's resource cache, may be null.

directFontCache:Map<COSName, SoftReference<PDFont>>

The document's direct font cache. Must be mutable

Method Detail

addback to summary
public COSName add(PDFont font)

Adds the given font to the resources of the current page and returns the name for the new resources. Returns the existing resource name if the given item already exists.

Parameters
font:PDFont

the font to add

Returns:COSName

the name of the resource in the resources dictionary

addback to summary
public COSName add(PDColorSpace colorSpace)

Adds the given color space to the resources of the current page and returns the name for the new resources. Returns the existing resource name if the given item already exists.

Parameters
colorSpace:PDColorSpace

the color space to add

Returns:COSName

the name of the resource in the resources dictionary

addback to summary
public COSName add(PDExtendedGraphicsState extGState)

Adds the given extended graphics state to the resources of the current page and returns the name for the new resources. Returns the existing resource name if the given item already exists.

Parameters
extGState:PDExtendedGraphicsState

the extended graphics state to add

Returns:COSName

the name of the resource in the resources dictionary

addback to summary
public COSName add(PDShading shading)

Adds the given shading to the resources of the current page and returns the name for the new resources. Returns the existing resource name if the given item already exists.

Parameters
shading:PDShading

the shading to add

Returns:COSName

the name of the resource in the resources dictionary

addback to summary
public COSName add(PDAbstractPattern pattern)

Adds the given pattern to the resources of the current page and returns the name for the new resources. Returns the existing resource name if the given item already exists.

Parameters
pattern:PDAbstractPattern

the pattern to add

Returns:COSName

the name of the resource in the resources dictionary

addback to summary
public COSName add(PDPropertyList properties)

Adds the given property list to the resources of the current page and returns the name for the new resources. Returns the existing resource name if the given item already exists.

Parameters
properties:PDPropertyList

the property list to add

Returns:COSName

the name of the resource in the resources dictionary

addback to summary
public COSName add(PDImageXObject image)

Adds the given image to the resources of the current page and returns the name for the new resources. Returns the existing resource name if the given item already exists.

Parameters
image:PDImageXObject

the image to add

Returns:COSName

the name of the resource in the resources dictionary

addback to summary
public COSName add(PDFormXObject form)

Adds the given form to the resources of the current page and returns the name for the new resources. Returns the existing resource name if the given item already exists.

Parameters
form:PDFormXObject

the form to add

Returns:COSName

the name of the resource in the resources dictionary

addback to summary
public COSName add(PDXObject xobject, String prefix)

Adds the given XObject to the resources of the current page and returns the name for the new resources. Returns the existing resource name if the given item already exists.

Parameters
xobject:PDXObject

the XObject to add

prefix:String

the prefix to be used when creating the resource name

Returns:COSName

the name of the resource in the resources dictionary

addback to summary
private COSName add(COSName kind, String prefix, COSObjectable object)

Adds the given resource if it does not already exist.

createKeyback to summary
private COSName createKey(COSName kind, String prefix)

Returns a unique key for a new resource.

getback to summary
private COSBase get(COSName kind, COSName name)

Returns the resource with the given name and kind, or null.

getColorSpaceback to summary
public PDColorSpace getColorSpace(COSName name) throws IOException

Returns the color space resource with the given name, or null if none exists.

Parameters
name:COSName

Name of the color space resource.

Returns:PDColorSpace

a new color space.

Exceptions
IOException:
if something went wrong.
getColorSpaceback to summary
public PDColorSpace getColorSpace(COSName name, boolean wasDefault) throws IOException

Returns the color space resource with the given name, or null if none exists. This method is for PDFBox internal use only, others should use getColorSpace(COSName).

Parameters
name:COSName

Name of the color space resource.

wasDefault:boolean

if current color space was used by a default color space. This parameter is to

Returns:PDColorSpace

a new color space.

Exceptions
IOException:
if something went wrong.
getColorSpaceNamesback to summary
public Iterable<COSName> getColorSpaceNames()

Returns the names of the color space resources, if any.

Returns:Iterable<COSName>

an iterable containing all names of available colorspaces

getCOSObjectback to summary
public COSDictionary getCOSObject()

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

Returns the underlying dictionary.

Returns:COSDictionary

Doc from org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

The cos object that matches this Java object.

Annotations
@Override
getExtGStateback to summary
public PDExtendedGraphicsState getExtGState(COSName name)

Returns the extended graphics state resource with the given name, or null if none exists.

Parameters
name:COSName

Name of the graphics state resource.

Returns:PDExtendedGraphicsState

the extended graphics state with the given name or null

getExtGStateNamesback to summary
public Iterable<COSName> getExtGStateNames()

Returns the names of the extended graphics state resources, if any.

Returns:Iterable<COSName>

an iterable containing all names of available extended graphics states

getFontback to summary
public PDFont getFont(COSName name) throws IOException

Returns the font resource with the given name, or null if none exists.

Parameters
name:COSName

Name of the font resource.

Returns:PDFont

the font with the given name or null

Exceptions
IOException:
if something went wrong.
getFontNamesback to summary
public Iterable<COSName> getFontNames()

Returns the names of the font resources, if any.

Returns:Iterable<COSName>

an iterable containing all names of available fonts

getIndirectback to summary
private COSObject getIndirect(COSName kind, COSName name)

Returns the resource with the given name and kind as an indirect object, or null.

getNamesback to summary
private Iterable<COSName> getNames(COSName kind)

Returns the resource names of the given kind.

getPatternback to summary
public PDAbstractPattern getPattern(COSName name) throws IOException

Returns the pattern resource with the given name, or null if none exists.

Parameters
name:COSName

Name of the pattern resource.

Returns:PDAbstractPattern

the pattern with the given name or null

Exceptions
IOException:
if something went wrong.
getPatternNamesback to summary
public Iterable<COSName> getPatternNames()

Returns the names of the pattern resources, if any.

Returns:Iterable<COSName>

an iterable containing all names of available patterns

getPropertiesback to summary
public PDPropertyList getProperties(COSName name)

Returns the property list resource with the given name, or null if none exists.

Parameters
name:COSName

Name of the property list resource.

Returns:PDPropertyList

the property list with the given name or null

getPropertiesNamesback to summary
public Iterable<COSName> getPropertiesNames()

Returns the names of the property list resources, if any.

Returns:Iterable<COSName>

an iterable containing all names of available property lists

getResourceCacheback to summary
public ResourceCache getResourceCache()

Returns the resource cache associated with the Resources, or null if there is none.

Returns:ResourceCache

the resource cache associated with the resources, or null

getShadingback to summary
public PDShading getShading(COSName name) throws IOException

Returns the shading resource with the given name, or null if none exists.

Parameters
name:COSName

Name of the shading resource.

Returns:PDShading

the shading state with the given name or null

Exceptions
IOException:
if something went wrong.
getShadingNamesback to summary
public Iterable<COSName> getShadingNames()

Returns the names of the shading resources, if any.

Returns:Iterable<COSName>

an iterable containing all names of available shadings

getXObjectback to summary
public PDXObject getXObject(COSName name) throws IOException

Returns the XObject resource with the given name, or null if none exists.

Parameters
name:COSName

Name of the XObject resource.

Returns:PDXObject

the XObject with the given name or null

Exceptions
IOException:
if something went wrong.
getXObjectNamesback to summary
public Iterable<COSName> getXObjectNames()

Returns the names of the XObject resources, if any.

Returns:Iterable<COSName>

an iterable containing all names of available xobjects

hasColorSpaceback to summary
public boolean hasColorSpace(COSName name)

Returns true if the given color space name exists in these resources.

Parameters
name:COSName

Name of the color space resource.

Returns:boolean

true if the given color space name exists in these resources, otherwise false

isAllowedCacheback to summary
private boolean isAllowedCache(PDXObject xobject)
isImageXObjectback to summary
public boolean isImageXObject(COSName name)

Tells whether the XObject resource with the given name is an image.

Parameters
name:COSName

Name of the XObject resource.

Returns:boolean

true if it is an image XObject, false if not.

putback to summary
private void put(COSName kind, COSName name, COSObjectable object)

Sets the value of a given named resource.

putback to summary
public void put(COSName name, PDFont font)

Sets the font resource with the given name.

Parameters
name:COSName

the name of the resource

font:PDFont

the font to be added

putback to summary
public void put(COSName name, PDColorSpace colorSpace)

Sets the color space resource with the given name.

Parameters
name:COSName

the name of the resource

colorSpace:PDColorSpace

the color space to be added

putback to summary
public void put(COSName name, PDExtendedGraphicsState extGState)

Sets the extended graphics state resource with the given name.

Parameters
name:COSName

the name of the resource

extGState:PDExtendedGraphicsState

the extended graphics state to be added

putback to summary
public void put(COSName name, PDShading shading)

Sets the shading resource with the given name.

Parameters
name:COSName

the name of the resource

shading:PDShading

the shading to be added

putback to summary
public void put(COSName name, PDAbstractPattern pattern)

Sets the pattern resource with the given name.

Parameters
name:COSName

the name of the resource

pattern:PDAbstractPattern

the pattern to be added

putback to summary
public void put(COSName name, PDPropertyList properties)

Sets the property list resource with the given name.

Parameters
name:COSName

the name of the resource

properties:PDPropertyList

the property list to be added

putback to summary
public void put(COSName name, PDXObject xobject)

Sets the XObject resource with the given name.

Parameters
name:COSName

the name of the resource

xobject:PDXObject

the XObject to be added