org.apache.pdfbox.pdmodel

## Class PDResources

- java.lang.Object
- - org.apache.pdfbox.pdmodel.PDResources

All Implemented Interfaces:
  COSObjectable

    public final class PDResources
    extends Object
    implements COSObjectable

A set of resources available at the page/pages/stream level.

Author:
  Ben Litchfield, John Hewson

### Constructor Summary

Constructors
Constructor and Description
`PDResources()` Constructor for embedding.
`PDResources(COSDictionary resourceDictionary)` Constructor for reading.
`PDResources(COSDictionary resourceDictionary, ResourceCache resourceCache)` Constructor for reading.
`PDResources(COSDictionary resourceDictionary, ResourceCache resourceCache, Map<COSName,SoftReference<PDFont>> directFontCache)` Constructor for reading.

### Method Summary

All Methods Instance Methods Concrete Methods
`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(PDColorSpace colorSpace)` Adds the given color space 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.
`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(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(PDPropertyList properties)` Adds the given property list 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(PDXObject xobject, String prefix)` Adds the given XObject to the resources of the current page and returns the name for the new resources.
`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.
`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.
`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.
`Iterable<COSName>` `getFontNames()` Returns the names of the font resources, if any.
`PDAbstractPattern` `getPattern(COSName name)` Returns the pattern resource with the given name, or null if none exists.
`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.
`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.
`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.
`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.
`boolean` `isImageXObject(COSName name)` Tells whether the XObject resource with the given name is an image.
`void` `put(COSName name, PDAbstractPattern pattern)` Sets the pattern resource with the given name.
`void` `put(COSName name, PDColorSpace colorSpace)` Sets the color space resource with the given name.
`void` `put(COSName name, PDExtendedGraphicsState extGState)` Sets the extended graphics state resource with the given name.
`void` `put(COSName name, PDFont font)` Sets the font resource with the given name.
`void` `put(COSName name, PDPropertyList properties)` Sets the property list resource with the given name.
`void` `put(COSName name, PDShading shading)` Sets the shading resource with the given name.
`void` `put(COSName name, PDXObject xobject)` Sets the XObject resource with the given name.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

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

#### PDResources

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

Constructor for reading.

Parameters:
  `resourceDictionary` - The cos dictionary for this resource.
  `resourceCache` - The document's resource cache, may be null.
  `directFontCache` - The document's direct font cache. Must be mutable

### Method Detail

#### getCOSObject

    public COSDictionary getCOSObject()

Returns the underlying dictionary.

Specified by:
  `getCOSObject` in interface `COSObjectable`
Returns:
  The cos object that matches this Java object.

#### getFont

    public PDFont getFont(COSName name)
                   throws 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:
  `IOException` - if something went wrong.

#### getColorSpace

    public PDColorSpace getColorSpace(COSName name)
                               throws 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:
  `IOException` - if something went wrong.

#### getColorSpace

    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` - 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:
  `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 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:
  `IOException` - if something went wrong.

#### getPattern

    public PDAbstractPattern getPattern(COSName name)
                                 throws 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:
  `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 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:
  `IOException` - if something went wrong.

#### getColorSpaceNames

    public Iterable<COSName> getColorSpaceNames()

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

Returns:
  the names of all color space resources.

#### getXObjectNames

    public Iterable<COSName> getXObjectNames()

Returns the names of the XObject resources, if any.

Returns:
  the names of all XObject resources.

#### getFontNames

    public Iterable<COSName> getFontNames()

Returns the names of the font resources, if any.

Returns:
  the names of all font resources.

#### getPropertiesNames

    public Iterable<COSName> getPropertiesNames()

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

Returns:
  the names of all property list resources.

#### getShadingNames

    public Iterable<COSName> getShadingNames()

Returns the names of the shading resources, if any.

Returns:
  the names of all shading resources.

#### getPatternNames

    public Iterable<COSName> getPatternNames()

Returns the names of the pattern resources, if any.

Returns:
  the names of all pattern resources.

#### getExtGStateNames

    public Iterable<COSName> getExtGStateNames()

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

Returns:
  the names of all extended graphics state resources.

#### 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,
                       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 add
  `prefix` - the prefix to be used when creating the resource name
Returns:
  the name of the resource in the resources dictionary

#### put

    public void put(COSName name,
                    PDFont font)

Sets the font resource with the given name.

Parameters:
  `name` - the name of the resource
  `font` - 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 resource
  `colorSpace` - 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 resource
  `extGState` - 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 resource
  `shading` - 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 resource
  `pattern` - 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 resource
  `properties` - 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 resource
  `xobject` - 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.