Class PdfResources


public class PdfResources extends PdfObjectWrapper<PdfDictionary>
Wrapper class that represent resource dictionary - that define named resources used by content streams operators. (ISO 32000-1, 7.8.3 Resource Dictionaries)
  • Constructor Details

    • PdfResources

      public PdfResources (PdfDictionary pdfObject)
      Creates new instance from given dictionary.
      Parameters:
      pdfObject - the PdfDictionary object from which the resource object will be created.
    • PdfResources

      public PdfResources()
      Creates new instance from empty dictionary.
  • Method Details

    • addFont

      public PdfName addFont (PdfDocument pdfDocument, PdfFont font)
      Adds font to resources and registers PdfFont in the document for further flushing.
      Parameters:
      pdfDocument - a PdfDocument instance to which the font is added for further flushing
      font - a PdfFont instance to be added
      Returns:
      added font resource name.
    • addImage

      public PdfName addImage (PdfImageXObject image)
      Adds PdfImageXObject object to the resources.
      Parameters:
      image - the PdfImageXObject to add.
      Returns:
      added image resource name.
    • addImage

      public PdfName addImage (PdfStream image)
      Adds PdfStream to the resources as image.
      Parameters:
      image - the PdfStream to add.
      Returns:
      added image resources name.
    • getImage

      public PdfImageXObject getImage (PdfName name)
    • addForm

      public PdfName addForm (PdfFormXObject form)
      Adds PdfFormXObject object to the resources.
      Parameters:
      form - the PdfFormXObject to add.
      Returns:
      added form resource name.
    • addForm

      public PdfName addForm (PdfStream form)
      Adds PdfStream to the resources as form.
      Parameters:
      form - the PdfStream to add.
      Returns:
      added form resources name.
    • addForm

      public PdfName addForm (PdfFormXObject form, PdfName name)
      Adds the given Form XObject to the current instance of PdfResources.
      Parameters:
      form - Form XObject.
      name - Preferred name for the given Form XObject.
      Returns:
      the PdfName of the newly added resource
    • getForm

      public PdfFormXObject getForm (PdfName name)
    • addExtGState

      public PdfName addExtGState (PdfExtGState extGState)
      Adds PdfExtGState object to the resources.
      Parameters:
      extGState - the PdfExtGState to add.
      Returns:
      added graphics state parameter dictionary resource name.
    • addExtGState

      public PdfName addExtGState (PdfDictionary extGState)
      Adds PdfDictionary to the resources as graphics state parameter dictionary.
      Parameters:
      extGState - the PdfDictionary to add.
      Returns:
      added graphics state parameter dictionary resources name.
    • getPdfExtGState

      public PdfExtGState getPdfExtGState (PdfName name)
    • addProperties

      public PdfName addProperties (PdfDictionary properties)
      Adds PdfDictionary to the resources as properties list.
      Parameters:
      properties - the PdfDictionary to add.
      Returns:
      added properties list resources name.
    • getProperties

      public PdfObject getProperties (PdfName name)
    • addColorSpace

      public PdfName addColorSpace (PdfColorSpace cs)
      Adds PdfColorSpace object to the resources.
      Parameters:
      cs - the PdfColorSpace to add.
      Returns:
      added color space resource name.
    • addColorSpace

      public PdfName addColorSpace (PdfObject colorSpace)
      Adds PdfObject to the resources as color space.
      Parameters:
      colorSpace - the PdfObject to add.
      Returns:
      added color space resources name.
    • getColorSpace

      public PdfColorSpace getColorSpace (PdfName name)
    • addPattern

      public PdfName addPattern (PdfPattern pattern)
      Adds PdfPattern object to the resources.
      Parameters:
      pattern - the PdfPattern to add.
      Returns:
      added pattern resource name.
    • addPattern

      public PdfName addPattern (PdfDictionary pattern)
      Adds PdfDictionary to the resources as pattern.
      Parameters:
      pattern - the PdfDictionary to add.
      Returns:
      added pattern resources name.
    • getPattern

      public PdfPattern getPattern (PdfName name)
    • addShading

      public PdfName addShading (PdfShading shading)
      Adds PdfShading object to the resources.
      Parameters:
      shading - the PdfShading to add.
      Returns:
      added shading resource name.
    • addShading

      public PdfName addShading (PdfDictionary shading)
      Adds PdfDictionary to the resources as shading dictionary.
      Parameters:
      shading - the PdfDictionary to add.
      Returns:
      added shading dictionary resources name.
    • getShading

      public PdfShading getShading (PdfName name)
    • isReadOnly

      protected boolean isReadOnly()
    • setReadOnly

      protected void setReadOnly (boolean readOnly)
    • isModified

      protected boolean isModified()
    • setModified

      public PdfObjectWrapper<PdfDictionary> setModified()
      Overrides:
      setModified in class PdfObjectWrapper<PdfDictionary>
    • setDefaultGray

      public void setDefaultGray (PdfColorSpace defaultCs)
      Sets the value of default Gray Color Space (see ISO-320001 Paragraph 8.6.5.6).
      Parameters:
      defaultCs - the color space to set.
    • setDefaultRgb

      public void setDefaultRgb (PdfColorSpace defaultCs)
      Sets the value of default RGB Color Space (see ISO-320001 Paragraph 8.6.5.6).
      Parameters:
      defaultCs - the color space to set.
    • setDefaultCmyk

      public void setDefaultCmyk (PdfColorSpace defaultCs)
      Sets the value of default CMYK Color Space (see ISO-320001 Paragraph 8.6.5.6).
      Parameters:
      defaultCs - the color space to set.
    • getResourceName

      public PdfObject> PdfName getResourceName (PdfObjectWrapper resource)
      Gets the mapped resource name of the PdfObject under the given wrapper.

      Note: if the name for the object won't be found, then the name of object's Indirect Reference will be searched.
      Type Parameters:
      T - the type of the underlined PdfObject in wrapper.
      Parameters:
      resource - the wrapper of the PdfObject, for which the name will be searched.
      Returns:
      the mapped resource name or null if object isn't added to resources.
    • getResourceName

      public PdfName getResourceName (PdfObject resource)
      Gets the mapped resource name of the given PdfObject.

      Note: if the name for the object won't be found, then the name of object's Indirect Reference will be searched.
      Parameters:
      resource - the object, for which the name will be searched.
      Returns:
      the mapped resource name or null if object isn't added to resources.
    • getResourceNames

      public Set<PdfName> getResourceNames()
      Gets the names of all the added resources.
      Returns:
      the name of all the added resources.
    • getProcSet

      public PdfArray getProcSet()
      Gets the array of predefined procedure set names (see ISO-320001 Paragraph 14.2). Deprecated in PDF 2.0.
      Returns:
      the array of predefined procedure set names.
    • setProcSet

      public void setProcSet (PdfArray array)
      Sets the array of predefined procedure set names (see ISO-320001 Paragraph 14.2). Deprecated in PDF 2.0.
      Parameters:
      array - the array of predefined procedure set names to be set.
    • getResourceNames

      public Set<PdfName> getResourceNames (PdfName resType)
      Gets the names of all resources of specified type.
      Parameters:
      resType - the resource type. Should be PdfName.ColorSpace, PdfName.ExtGState, PdfName.Pattern, PdfName.Shading, PdfName.XObject, PdfName.Font.
      Returns:
      set of resources name of corresponding type. May be empty. Will be empty in case of incorrect resource type.
    • getResource

      public PdfDictionary getResource (PdfName resType)
      Get the PdfDictionary object that that contain resources of specified type.
      Parameters:
      resType - the resource type. Should be PdfName.ColorSpace, PdfName.ExtGState, PdfName.Pattern, PdfName.Shading, PdfName.XObject, PdfName.Font.
      Returns:
      the PdfDictionary object containing all resources of specified type, or null in case of incorrect resource type.
    • getResourceObject

      public PdfObject getResourceObject (PdfName resType, PdfName resName)
      Get the PdfObject object with specified type and name.
      Parameters:
      resType - the resource type. Should be PdfName.ColorSpace, PdfName.ExtGState, PdfName.Pattern, PdfName.Shading, PdfName.XObject, PdfName.Font.
      resName - the name of the resource object.
      Returns:
      the PdfObject with specified name in the resources of specified type or null in case of incorrect type or missing resource with such name.
    • isWrappedObjectMustBeIndirect

      protected boolean isWrappedObjectMustBeIndirect()
      Description copied from class: PdfObjectWrapper
      Defines if the object behind this wrapper must be an indirect object in the resultant document.

      If this method returns true it doesn't necessarily mean that object must be in the indirect state at any moment, but rather defines that when the object will be written to the document it will be transformed into indirect object if it's not indirect yet.

      Return value of this method shouldn't depend on any logic, it should return always true or false.
      Specified by:
      isWrappedObjectMustBeIndirect in class PdfObjectWrapper<PdfDictionary>
      Returns:
      true if in the resultant document the object behind the wrapper must be indirect, otherwise false.
    • addResource

      protected void addResource (PdfObject resource, PdfName resType, PdfName resName)
    • buildResources

      protected void buildResources (PdfDictionary dictionary)