Class PdfDictionary

  • Direct Known Subclasses:
    PdfStream

    public class PdfDictionary
    extends PdfObject
    A representation of a Dictionary as described by the PDF Specification. A Dictionary is a mapping between keys and values. Keys are PdfNames and the values are PdfObjects. Each key can only be associated with one value and adding a new value to an existing key will override the previous value. A value of null should be ignored when the PdfDocument is closed.
    • Constructor Detail

      • PdfDictionary

        public PdfDictionary()
        Creates a new PdfDictionary instance.
      • PdfDictionary

        public PdfDictionary​(java.util.Map<PdfName,​PdfObject> map)
        Creates a new PdfDictionary instance. This constructor inserts the content of the specified Map into this PdfDictionary instance.
        Parameters:
        map - Map containing values to be inserted into PdfDictionary
      • PdfDictionary

        public PdfDictionary​(java.util.Set<java.util.Map.Entry<PdfName,​PdfObject>> entrySet)
        Creates a new PdfDictionary instance. This constructor inserts the content of the specified Set into this PdfDictionary instance.
        Parameters:
        entrySet - Set containing Map#Entries to be inserted into PdfDictionary
      • PdfDictionary

        public PdfDictionary​(PdfDictionary dictionary)
        Creates a new PdfDictionary instance. This constructor inserts the content of the specified PdfDictionary into this PdfDictionary instance.
        Parameters:
        dictionary - PdfDictionary containing values to be inserted into PdfDictionary
    • Method Detail

      • size

        public int size()
        Returns the number of key-value pairs in this PdfDictionary.
        Returns:
        number of key-value pairs
      • isEmpty

        public boolean isEmpty()
        Returns true if there are no key-value pairs in this PdfDictionary.
        Returns:
        true if there are no key-value pairs in this PdfDictionary
      • containsKey

        public boolean containsKey​(PdfName key)
        Returns true if this PdfDictionary contains the specified key.
        Parameters:
        key - the key to check
        Returns:
        true if key is present in the PdfDictionary
      • containsValue

        public boolean containsValue​(PdfObject value)
        Returns true if this PdfDictionary contains the specified value.
        Parameters:
        value - the value to check
        Returns:
        true if value is present in the PdfDictionary
      • get

        public PdfObject get​(PdfName key)
        Returns the value associated to this key.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        the value associated with this key
      • getAsArray

        public PdfArray getAsArray​(PdfName key)
        Returns the value associated to this key as a PdfArray. If the value isn't a PdfArray, null is returned.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        PdfArray associated with this key
      • getAsDictionary

        public PdfDictionary getAsDictionary​(PdfName key)
        Returns the value associated to this key as a PdfDictionary. If the value isn't a PdfDictionary, null is returned.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        PdfDictionary associated with this key
      • getAsStream

        public PdfStream getAsStream​(PdfName key)
        Returns the value associated to this key as a PdfStream. If the value isn't a PdfStream, null is returned.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        PdfStream associated with this key
      • getAsNumber

        public PdfNumber getAsNumber​(PdfName key)
        Returns the value associated to this key as a PdfNumber. If the value isn't a PdfNumber, null is returned.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        PdfNumber associated with this key
      • getAsName

        public PdfName getAsName​(PdfName key)
        Returns the value associated to this key as a PdfName. If the value isn't a PdfName, null is returned.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        PdfName associated with this key
      • getAsString

        public PdfString getAsString​(PdfName key)
        Returns the value associated to this key as a PdfString. If the value isn't a PdfString, null is returned.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        PdfString associated with this key
      • getAsBoolean

        public PdfBoolean getAsBoolean​(PdfName key)
        Returns the value associated to this key as a PdfBoolean. If the value isn't a PdfBoolean, null is returned.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        PdfBoolean associated with this key
      • getAsRectangle

        public Rectangle getAsRectangle​(PdfName key)
        Returns the value associated to this key as a Rectangle. If the value isn't a PdfArray of which the firt four elements are PdfNumbers, null is returned.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        PdfArray associated with this key
        See Also:
        PdfArray.toRectangle()
      • getAsFloat

        public java.lang.Float getAsFloat​(PdfName key)
        Returns the value associated to this key as a Float. If the value isn't a Pdfnumber, null is returned.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        Float associated with this key
      • getAsInt

        public java.lang.Integer getAsInt​(PdfName key)
        Returns the value associated to this key as an Integer. If the value isn't a Pdfnumber, null is returned.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        Integer associated with this key
      • getAsBool

        public java.lang.Boolean getAsBool​(PdfName key)
        Returns the value associated to this key as a Boolean. If the value isn't a PdfBoolean, null is returned.
        Parameters:
        key - the key of which the associated value needs to be returned
        Returns:
        Boolean associated with this key
      • put

        public PdfObject put​(PdfName key,
                             PdfObject value)
        Inserts the value into this PdfDictionary and associates it with the specified key. If the key is already present in this PdfDictionary, this method will override the old value with the specified one.
        Parameters:
        key - key to insert or to override
        value - the value to associate with the specified key
        Returns:
        the previous PdfObject associated with this key
      • remove

        public PdfObject remove​(PdfName key)
        Removes the specified key from this PdfDictionary.
        Parameters:
        key - key to be removed
        Returns:
        the removed value associated with the specified key
      • putAll

        public void putAll​(PdfDictionary d)
        Inserts all the key-value pairs into this PdfDictionary.
        Parameters:
        d - PdfDictionary holding the key-value pairs to be copied
      • clear

        public void clear()
        Removes all key-value pairs from this PdfDictionary.
      • keySet

        public java.util.Set<PdfName> keySet()
        Returns all the keys of this PdfDictionary as a Set.
        Returns:
        Set of keys
      • values

        public java.util.Collection<PdfObject> values​(boolean asDirects)
        Returns all the values of this map in a Collection.
        Parameters:
        asDirects - if false, collection will contain PdfIndirectReference instances for the indirect objects in dictionary, otherwise it will contain collection of direct objects.
        Returns:
        a Collection holding all the values
      • values

        public java.util.Collection<PdfObject> values()
        Returns all the values of this map in a Collection.
        NOTE: since 7.0.1 it returns collection of direct objects. If you want to get PdfIndirectReference instances for the indirect objects value, you shall use values(boolean) method.
        Returns:
        a Collection holding all the values
      • entrySet

        public java.util.Set<java.util.Map.Entry<PdfName,​PdfObject>> entrySet()
        Returns a Set holding the key-value pairs as Map#Entry objects.
        NOTE: since 7.0.1 it returns collection of direct objects. If you want to get PdfIndirectReference instances for the indirect objects value, you shall use get(PdfName, boolean) method.
        Returns:
        a Set of Map.Entry objects
      • getType

        public byte getType()
        Description copied from class: PdfObject
        Gets object type.
        Specified by:
        getType in class PdfObject
        Returns:
        object type.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • clone

        public PdfDictionary clone​(java.util.List<PdfName> excludeKeys)
        Creates clones of the dictionary in the current document. It's possible to pass a list of keys to exclude when cloning.
        Parameters:
        excludeKeys - list of objects to exclude when cloning dictionary.
        Returns:
        cloned dictionary.
      • copyTo

        public PdfDictionary copyTo​(PdfDocument document,
                                    java.util.List<PdfName> excludeKeys,
                                    boolean allowDuplicating)
        Copies dictionary to specified document. It's possible to pass a list of keys to exclude when copying.
        Parameters:
        document - document to copy dictionary to.
        excludeKeys - list of objects to exclude when copying dictionary.
        allowDuplicating - PdfObject.copyTo(PdfDocument, boolean)
        Returns:
        copied dictionary.
      • copyTo

        public PdfDictionary copyTo​(PdfDocument document,
                                    java.util.List<PdfName> excludeKeys,
                                    boolean allowDuplicating,
                                    ICopyFilter copyFilter)
        Copies dictionary to specified document. It's possible to pass a list of keys to exclude when copying.
        Parameters:
        document - document to copy dictionary to.
        excludeKeys - list of objects to exclude when copying dictionary.
        allowDuplicating - PdfObject.copyTo(PdfDocument, boolean)
        copyFilter - ICopyFilter a filter to apply while copying arrays and dictionaries Use NullCopyFilter for no filtering
        Returns:
        copied dictionary.
      • get

        public PdfObject get​(PdfName key,
                             boolean asDirect)
        Parameters:
        asDirect - true is to extract direct object always.
        key - the key to get the value from the map
        Returns:
        key if indirect reference is present
      • mergeDifferent

        public void mergeDifferent​(PdfDictionary other)
        This method merges different fields from two dictionaries into the current one
        Parameters:
        other - a dictionary whose fields should be merged into the current dictionary.
      • newInstance

        protected PdfObject newInstance()
        Description copied from class: PdfObject
        Creates new instance of object.
        Specified by:
        newInstance in class PdfObject
        Returns:
        new instance of object.
      • copyContent

        protected void copyContent​(PdfObject from,
                                   PdfDocument document)
        Copies object content from object 'from'.
        Overrides:
        copyContent in class PdfObject
        Parameters:
        from - object to copy content from.
        document - document to copy object to.
      • copyContent

        protected void copyContent​(PdfObject from,
                                   PdfDocument document,
                                   ICopyFilter copyFilter)
        Copies object content from object 'from'.
        Overrides:
        copyContent in class PdfObject
        Parameters:
        from - object to copy content from.
        document - document to copy object to.
        copyFilter - ICopyFilter a filter that will apply on dictionaries and array Use NullCopyFilter for no filtering
      • releaseContent

        protected void releaseContent()
        Release content of PdfDictionary.