Package org.apache.pdfbox.pdmodel
Class PDResources
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.PDResources
-
- All Implemented Interfaces:
COSObjectable
public final class PDResources extends java.lang.Object implements COSObjectable
A set of resources available at the page/pages/stream level.
-
-
Field Summary
Fields Modifier and Type Field Description private ResourceCache
cache
private java.util.Map<COSName,java.lang.ref.SoftReference<PDFont>>
directFontCache
private COSDictionary
resources
-
Constructor Summary
Constructors Constructor Description PDResources()
Constructor for embedding.PDResources(COSDictionary resourceDictionary)
Constructor for reading.PDResources(COSDictionary resourceDictionary, ResourceCache resourceCache)
Constructor for reading.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private COSName
add(COSName kind, java.lang.String prefix, COSObjectable object)
Adds the given resource if it does not already exist.COSName
add(PDPropertyList properties)
Adds the given property list to the resources of the current page and returns the name for the new resources.COSName
add(PDFont font)
Adds the given font to the resources of the current page and returns the name for the new resources.COSName
add(PDColorSpace colorSpace)
Adds the given color space to the resources of the current page and returns the name for the new resources.COSName
add(PDFormXObject form)
Adds the given form to the resources of the current page and returns the name for the new resources.COSName
add(PDImageXObject image)
Adds the given image to the resources of the current page and returns the name for the new resources.COSName
add(PDAbstractPattern pattern)
Adds the given pattern to the resources of the current page and returns the name for the new resources.COSName
add(PDXObject xobject, java.lang.String prefix)
Adds the given XObject to the resources of the current page and returns the name for the new resources.COSName
add(PDShading shading)
Adds the given shading to the resources of the current page and returns the name for the new resources.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.private COSName
createKey(COSName kind, java.lang.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.PDColorSpace
getColorSpace(COSName name)
Returns the color space resource with the given name, or null if none exists.PDColorSpace
getColorSpace(COSName name, boolean wasDefault)
Returns the color space resource with the given name, or null if none exists.java.lang.Iterable<COSName>
getColorSpaceNames()
Returns the names of the color space resources, if any.COSDictionary
getCOSObject()
Returns the underlying dictionary.PDExtendedGraphicsState
getExtGState(COSName name)
Returns the extended graphics state resource with the given name, or null if none exists.java.lang.Iterable<COSName>
getExtGStateNames()
Returns the names of the extended graphics state resources, if any.PDFont
getFont(COSName name)
Returns the font resource with the given name, or null if none exists.java.lang.Iterable<COSName>
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 java.lang.Iterable<COSName>
getNames(COSName kind)
Returns the resource names of the given kind.PDAbstractPattern
getPattern(COSName name)
Returns the pattern resource with the given name, or null if none exists.java.lang.Iterable<COSName>
getPatternNames()
Returns the names of the pattern resources, if any.PDPropertyList
getProperties(COSName name)
Returns the property list resource with the given name, or null if none exists.java.lang.Iterable<COSName>
getPropertiesNames()
Returns the names of the property list resources, if any.ResourceCache
getResourceCache()
Returns the resource cache associated with the Resources, or null if there is none.PDShading
getShading(COSName name)
Returns the shading resource with the given name, or null if none exists.java.lang.Iterable<COSName>
getShadingNames()
Returns the names of the shading resources, if any.PDXObject
getXObject(COSName name)
Returns the XObject resource with the given name, or null if none exists.java.lang.Iterable<COSName>
getXObjectNames()
Returns the names of the XObject resources, if any.boolean
hasColorSpace(COSName name)
Returns true if the given color space name exists in these resources.private boolean
isAllowedCache(PDXObject xobject)
boolean
isImageXObject(COSName 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.void
put(COSName name, PDPropertyList properties)
Sets the property list resource with the given name.void
put(COSName name, PDFont font)
Sets the font resource with the given name.void
put(COSName name, PDColorSpace colorSpace)
Sets the color space resource with the given name.void
put(COSName name, PDAbstractPattern pattern)
Sets the pattern resource with the given name.void
put(COSName name, PDXObject xobject)
Sets the XObject resource with the given name.void
put(COSName name, PDShading shading)
Sets the shading resource with the given name.void
put(COSName name, PDExtendedGraphicsState extGState)
Sets the extended graphics state resource with the given name.
-
-
-
Field Detail
-
resources
private final COSDictionary resources
-
cache
private final ResourceCache cache
-
-
Constructor Detail
-
PDResources
public PDResources()
Constructor for embedding.
-
PDResources
public PDResources(COSDictionary resourceDictionary)
Constructor for reading.- Parameters:
resourceDictionary
- The cos dictionary for this resource.
-
PDResources
public PDResources(COSDictionary resourceDictionary, ResourceCache resourceCache)
Constructor for reading.- Parameters:
resourceDictionary
- The cos dictionary for this resource.resourceCache
- The document's resource cache, may be null.
-
-
Method Detail
-
getCOSObject
public COSDictionary getCOSObject()
Returns the underlying dictionary.- Specified by:
getCOSObject
in interfaceCOSObjectable
- Returns:
- The cos object that matches this Java object.
-
getFont
public PDFont getFont(COSName name) throws java.io.IOException
Returns the font resource with the given name, or null if none exists.- Parameters:
name
- Name of the font resource.- Returns:
- the font resource with the given name.
- Throws:
java.io.IOException
- if something went wrong.
-
getColorSpace
public PDColorSpace getColorSpace(COSName name) throws java.io.IOException
Returns the color space resource with the given name, or null if none exists.- Parameters:
name
- Name of the color space resource.- Returns:
- a new color space.
- Throws:
java.io.IOException
- if something went wrong.
-
getColorSpace
public PDColorSpace getColorSpace(COSName name, boolean wasDefault) throws java.io.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 usegetColorSpace(COSName)
.- Parameters:
name
- Name of the color space resource.wasDefault
- if current color space was used by a default color space. This parameter is to- Returns:
- a new color space.
- Throws:
java.io.IOException
- if something went wrong.
-
hasColorSpace
public boolean hasColorSpace(COSName name)
Returns true if the given color space name exists in these resources.- Parameters:
name
- Name of the color space resource.- Returns:
- true if the color space with the given name exists.
-
getExtGState
public PDExtendedGraphicsState getExtGState(COSName name)
Returns the extended graphics state resource with the given name, or null if none exists.- Parameters:
name
- Name of the graphics state resource.- Returns:
- the extended graphics state resource with the given name.
-
getShading
public PDShading getShading(COSName name) throws java.io.IOException
Returns the shading resource with the given name, or null if none exists.- Parameters:
name
- Name of the shading resource.- Returns:
- the shading resource of the given name.
- Throws:
java.io.IOException
- if something went wrong.
-
getPattern
public PDAbstractPattern getPattern(COSName name) throws java.io.IOException
Returns the pattern resource with the given name, or null if none exists.- Parameters:
name
- Name of the pattern resource.- Returns:
- the pattern resource of the given name.
- Throws:
java.io.IOException
- if something went wrong.
-
getProperties
public PDPropertyList getProperties(COSName name)
Returns the property list resource with the given name, or null if none exists.- Parameters:
name
- Name of the property list resource.- Returns:
- the property list resource of the given name.
-
isImageXObject
public boolean isImageXObject(COSName name)
Tells whether the XObject resource with the given name is an image.- Parameters:
name
- Name of the XObject resource.- Returns:
- true if it is an image XObject, false if not.
-
getXObject
public PDXObject getXObject(COSName name) throws java.io.IOException
Returns the XObject resource with the given name, or null if none exists.- Parameters:
name
- Name of the XObject resource.- Returns:
- the XObject resource of the given name.
- Throws:
java.io.IOException
- if something went wrong.
-
isAllowedCache
private boolean isAllowedCache(PDXObject xobject)
-
getIndirect
private COSObject getIndirect(COSName kind, COSName name)
Returns the resource with the given name and kind as an indirect object, or null.
-
get
private COSBase get(COSName kind, COSName name)
Returns the resource with the given name and kind, or null.
-
getColorSpaceNames
public java.lang.Iterable<COSName> getColorSpaceNames()
Returns the names of the color space resources, if any.- Returns:
- the names of all color space resources.
-
getXObjectNames
public java.lang.Iterable<COSName> getXObjectNames()
Returns the names of the XObject resources, if any.- Returns:
- the names of all XObject resources.
-
getFontNames
public java.lang.Iterable<COSName> getFontNames()
Returns the names of the font resources, if any.- Returns:
- the names of all font resources.
-
getPropertiesNames
public java.lang.Iterable<COSName> getPropertiesNames()
Returns the names of the property list resources, if any.- Returns:
- the names of all property list resources.
-
getShadingNames
public java.lang.Iterable<COSName> getShadingNames()
Returns the names of the shading resources, if any.- Returns:
- the names of all shading resources.
-
getPatternNames
public java.lang.Iterable<COSName> getPatternNames()
Returns the names of the pattern resources, if any.- Returns:
- the names of all pattern resources.
-
getExtGStateNames
public java.lang.Iterable<COSName> getExtGStateNames()
Returns the names of the extended graphics state resources, if any.- Returns:
- the names of all extended graphics state resources.
-
getNames
private java.lang.Iterable<COSName> getNames(COSName kind)
Returns the resource names of the given kind.- Returns:
- the names of all resources of the given kind.
-
add
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
- the font to add- Returns:
- the name of the resource in the resources dictionary
-
add
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
- the color space to add- Returns:
- the name of the resource in the resources dictionary
-
add
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
- the extended graphics state to add- Returns:
- the name of the resource in the resources dictionary
-
add
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
- the shading to add- Returns:
- the name of the resource in the resources dictionary
-
add
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
- the pattern to add- Returns:
- the name of the resource in the resources dictionary
-
add
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
- the property list to add- Returns:
- the name of the resource in the resources dictionary
-
add
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
- the image to add- Returns:
- the name of the resource in the resources dictionary
-
add
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
- the form to add- Returns:
- the name of the resource in the resources dictionary
-
add
public COSName add(PDXObject xobject, java.lang.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
- the XObject to addprefix
- the prefix to be used when creating the resource name- Returns:
- the name of the resource in the resources dictionary
-
add
private COSName add(COSName kind, java.lang.String prefix, COSObjectable object)
Adds the given resource if it does not already exist.
-
createKey
private COSName createKey(COSName kind, java.lang.String prefix)
Returns a unique key for a new resource.
-
put
private void put(COSName kind, COSName name, COSObjectable object)
Sets the value of a given named resource.
-
put
public void put(COSName name, PDFont font)
Sets the font resource with the given name.- Parameters:
name
- the name of the resourcefont
- the font to be added
-
put
public void put(COSName name, PDColorSpace colorSpace)
Sets the color space resource with the given name.- Parameters:
name
- the name of the resourcecolorSpace
- the color space to be added
-
put
public void put(COSName name, PDExtendedGraphicsState extGState)
Sets the extended graphics state resource with the given name.- Parameters:
name
- the name of the resourceextGState
- the extended graphics state to be added
-
put
public void put(COSName name, PDShading shading)
Sets the shading resource with the given name.- Parameters:
name
- the name of the resourceshading
- the shading to be added
-
put
public void put(COSName name, PDAbstractPattern pattern)
Sets the pattern resource with the given name.- Parameters:
name
- the name of the resourcepattern
- the pattern to be added
-
put
public void put(COSName name, PDPropertyList properties)
Sets the property list resource with the given name.- Parameters:
name
- the name of the resourceproperties
- the property list to be added
-
put
public void put(COSName name, PDXObject xobject)
Sets the XObject resource with the given name.- Parameters:
name
- the name of the resourcexobject
- the XObject to be added
-
getResourceCache
public ResourceCache getResourceCache()
Returns the resource cache associated with the Resources, or null if there is none.- Returns:
- the resource cache associated with the resources.
-
-