Package org.apache.pdfbox.pdmodel
Class PDResources
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.PDResources
-
- All Implemented Interfaces:
COSObjectable
public class PDResources extends java.lang.Object implements COSObjectable
This represents a set of resources available at the page/pages/stream level.- Author:
- Ben Litchfield, BM
-
-
Constructor Summary
Constructors Constructor Description PDResources()
Default constructor.PDResources(COSDictionary resourceDictionary)
Prepopulated resources.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.String
addFont(PDFont font)
Adds the given font to the resources of the current page.java.lang.String
addFont(PDFont font, java.lang.String fontKey)
Adds the given font to the resources of the current page using the given font key.java.lang.String
addXObject(PDXObject xobject, java.lang.String prefix)
Adds the given XObject to the resources of the current the page.void
clear()
Calling this will release all cached information.java.util.Map<java.lang.String,PDColorSpace>
getColorSpaces()
This will get the map of colorspaces.COSDictionary
getCOSDictionary()
This will get the underlying dictionary.COSBase
getCOSObject()
Convert this standard java object to a COS object.java.util.Map<java.lang.String,PDFont>
getFonts()
This will get the map of fonts.java.util.Map<java.lang.String,PDFont>
getFonts(java.util.Map<java.lang.String,PDFont> fontCache)
Deprecated.due to some side effects font caching is no longer supported, usegetFonts()
insteadjava.util.Map<java.lang.String,PDExtendedGraphicsState>
getGraphicsStates()
This will get the map of graphic states.java.util.Map<java.lang.String,PDXObjectImage>
getImages()
Deprecated.usegetXObjects()
instead, as the images map isn't synchronized with the XObjects map.java.util.Map<java.lang.String,PDPatternResources>
getPatterns()
This will get the map of patterns.PDPropertyList
getProperties()
Returns the dictionary mapping resource names to property list dictionaries for marked content.java.util.Map<java.lang.String,PDShadingResources>
getShadings()
This will get the map of shadings.java.util.Map<java.lang.String,PDXObject>
getXObjects()
This will get the map of PDXObjects that are in the resource dictionary.void
setColorSpaces(java.util.Map<java.lang.String,PDColorSpace> csValue)
This will set the map of colorspaces.void
setFonts(java.util.Map<java.lang.String,PDFont> fontsValue)
This will set the map of fonts.void
setGraphicsStates(java.util.Map<java.lang.String,PDExtendedGraphicsState> states)
This will set the map of graphics states.void
setPatterns(java.util.Map<java.lang.String,PDPatternResources> patternsValue)
This will set the map of patterns.void
setProperties(PDPropertyList props)
Sets the dictionary mapping resource names to property list dictionaries for marked content.void
setShadings(java.util.Map<java.lang.String,PDShadingResources> shadingsValue)
This will set the map of shadings.void
setXObjects(java.util.Map<java.lang.String,PDXObject> xobjectsValue)
This will set the map of xobjects.
-
-
-
Constructor Detail
-
PDResources
public PDResources()
Default constructor.
-
PDResources
public PDResources(COSDictionary resourceDictionary)
Prepopulated resources.- Parameters:
resourceDictionary
- The cos dictionary for this resource.
-
-
Method Detail
-
getCOSDictionary
public COSDictionary getCOSDictionary()
This will get the underlying dictionary.- Returns:
- The dictionary for these resources.
-
getCOSObject
public COSBase getCOSObject()
Convert this standard java object to a COS object.- Specified by:
getCOSObject
in interfaceCOSObjectable
- Returns:
- The cos object that matches this Java object.
-
clear
public void clear()
Calling this will release all cached information.
-
getFonts
public java.util.Map<java.lang.String,PDFont> getFonts(java.util.Map<java.lang.String,PDFont> fontCache) throws java.io.IOException
Deprecated.due to some side effects font caching is no longer supported, usegetFonts()
insteadThis will get the map of fonts. This will never return null. The keys are string and the values are PDFont objects.- Parameters:
fontCache
- A map of existing PDFont objects to reuse.- Returns:
- The map of fonts.
- Throws:
java.io.IOException
- If there is an error getting the fonts.
-
getFonts
public java.util.Map<java.lang.String,PDFont> getFonts()
This will get the map of fonts. This will never return null.- Returns:
- The map of fonts.
-
getXObjects
public java.util.Map<java.lang.String,PDXObject> getXObjects()
This will get the map of PDXObjects that are in the resource dictionary. This will never return null.- Returns:
- The map of xobjects.
-
getImages
public java.util.Map<java.lang.String,PDXObjectImage> getImages() throws java.io.IOException
Deprecated.usegetXObjects()
instead, as the images map isn't synchronized with the XObjects map.This will get the map of images. An empty map will be returned if there are no underlying images. So far the keys are COSName of the image and the value is the corresponding PDXObjectImage.- Returns:
- The map of images.
- Throws:
java.io.IOException
- If there is an error writing the picture.
-
setFonts
public void setFonts(java.util.Map<java.lang.String,PDFont> fontsValue)
This will set the map of fonts.- Parameters:
fontsValue
- The new map of fonts.
-
setXObjects
public void setXObjects(java.util.Map<java.lang.String,PDXObject> xobjectsValue)
This will set the map of xobjects.- Parameters:
xobjectsValue
- The new map of xobjects.
-
getColorSpaces
public java.util.Map<java.lang.String,PDColorSpace> getColorSpaces()
This will get the map of colorspaces. This will return null if the underlying resources dictionary does not have a colorspace dictionary. The keys are string and the values are PDColorSpace objects.- Returns:
- The map of colorspaces.
-
setColorSpaces
public void setColorSpaces(java.util.Map<java.lang.String,PDColorSpace> csValue)
This will set the map of colorspaces.- Parameters:
csValue
- The new map of colorspaces.
-
getGraphicsStates
public java.util.Map<java.lang.String,PDExtendedGraphicsState> getGraphicsStates()
This will get the map of graphic states. This will return null if the underlying resources dictionary does not have a graphics dictionary. The keys are the graphic state name as a String and the values are PDExtendedGraphicsState objects.- Returns:
- The map of extended graphic state objects.
-
setGraphicsStates
public void setGraphicsStates(java.util.Map<java.lang.String,PDExtendedGraphicsState> states)
This will set the map of graphics states.- Parameters:
states
- The new map of states.
-
getProperties
public PDPropertyList getProperties()
Returns the dictionary mapping resource names to property list dictionaries for marked content.- Returns:
- the property list
-
setProperties
public void setProperties(PDPropertyList props)
Sets the dictionary mapping resource names to property list dictionaries for marked content.- Parameters:
props
- the property list
-
getPatterns
public java.util.Map<java.lang.String,PDPatternResources> getPatterns() throws java.io.IOException
This will get the map of patterns. This will return null if the underlying resources dictionary does not have a patterns dictionary. The keys are the pattern name as a String and the values are PDPatternResources objects.- Returns:
- The map of pattern resources objects.
- Throws:
java.io.IOException
- If there is an error getting the pattern resources.
-
setPatterns
public void setPatterns(java.util.Map<java.lang.String,PDPatternResources> patternsValue)
This will set the map of patterns.- Parameters:
patternsValue
- The new map of patterns.
-
getShadings
public java.util.Map<java.lang.String,PDShadingResources> getShadings() throws java.io.IOException
This will get the map of shadings. This will return null if the underlying resources dictionary does not have a shading dictionary. The keys are the shading name as a String and the values are PDShadingResources objects.- Returns:
- The map of shading resources objects.
- Throws:
java.io.IOException
- If there is an error getting the shading resources.
-
setShadings
public void setShadings(java.util.Map<java.lang.String,PDShadingResources> shadingsValue)
This will set the map of shadings.- Parameters:
shadingsValue
- The new map of shadings.
-
addFont
public java.lang.String addFont(PDFont font)
Adds the given font to the resources of the current page.- Parameters:
font
- the font to be added- Returns:
- the font name to be used within the content stream.
-
addFont
public java.lang.String addFont(PDFont font, java.lang.String fontKey)
Adds the given font to the resources of the current page using the given font key.- Parameters:
font
- the font to be addedfontKey
- key to used to map to the given font- Returns:
- the font name to be used within the content stream.
-
addXObject
public java.lang.String addXObject(PDXObject xobject, java.lang.String prefix)
Adds the given XObject to the resources of the current the page.- Parameters:
xobject
- the XObject to be addedprefix
- the prefix to be used for the name- Returns:
- the XObject name to be used within the content stream.
-
-