Class PDResources

  • All Implemented Interfaces:
    COSObjectable

    public final class PDResources
    extends Object
    implements COSObjectable
    A set of resources available at the page/pages/stream level.
    • 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 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.
        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.
        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.
      • getExtGState

        public PDExtendedGraphicsState getExtGState​(COSName name)
        Returns the external graphics state resource with the given name, or null if none exists.
        Parameters:
        name - Name of the graphics state resource.
      • 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.
        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.
        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.
      • 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.
        Throws:
        IOException - if something went wrong.
      • getColorSpaceNames

        public Iterable<COSName> getColorSpaceNames()
        Returns the names of the color space resources, if any.
      • getXObjectNames

        public Iterable<COSName> getXObjectNames()
        Returns the names of the XObject resources, if any.
      • getFontNames

        public Iterable<COSName> getFontNames()
        Returns the names of the font resources, if any.
      • getPropertiesNames

        public Iterable<COSName> getPropertiesNames()
        Returns the names of the property list resources, if any.
      • getShadingNames

        public Iterable<COSName> getShadingNames()
        Returns the names of the shading resources, if any.
      • getPatternNames

        public Iterable<COSName> getPatternNames()
        Returns the names of the pattern resources, if any.
      • getExtGStateNames

        public Iterable<COSName> getExtGStateNames()
        Returns the names of the extended graphics state resources, if any.
      • 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)
                 throws IOException
        Sets the color space resource with the given name.
        Parameters:
        name - the name of the resource
        colorSpace - the color space to be added
        Throws:
        IOException
      • 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.