Package com.itextpdf.kernel.pdf
Class PdfDictionary
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObject
-
- com.itextpdf.kernel.pdf.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 arePdfNames
and the values arePdfObjects
. 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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<PdfName,PdfObject>
map
-
Fields inherited from class com.itextpdf.kernel.pdf.PdfObject
ARRAY, BOOLEAN, DICTIONARY, FLUSHED, FORBID_RELEASE, FREE, INDIRECT_REFERENCE, indirectReference, LITERAL, MODIFIED, MUST_BE_FLUSHED, MUST_BE_INDIRECT, NAME, NULL, NUMBER, ORIGINAL_OBJECT_STREAM, READ_ONLY, READING, STREAM, STRING, UNENCRYPTED
-
-
Constructor Summary
Constructors Constructor Description PdfDictionary()
Creates a new PdfDictionary instance.PdfDictionary(PdfDictionary dictionary)
Creates a new PdfDictionary instance.PdfDictionary(java.util.Map<PdfName,PdfObject> map)
Creates a new PdfDictionary instance.PdfDictionary(java.util.Set<java.util.Map.Entry<PdfName,PdfObject>> entrySet)
Creates a new PdfDictionary instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all key-value pairs from this PdfDictionary.PdfDictionary
clone(java.util.List<PdfName> excludeKeys)
Creates clones of the dictionary in the current document.boolean
containsKey(PdfName key)
Returns true if this PdfDictionary contains the specified key.boolean
containsValue(PdfObject value)
Returns true if this PdfDictionary contains the specified value.protected void
copyContent(PdfObject from, PdfDocument document)
Copies object content from object 'from'.protected void
copyContent(PdfObject from, PdfDocument document, ICopyFilter copyFilter)
Copies object content from object 'from'.PdfDictionary
copyTo(PdfDocument document, java.util.List<PdfName> excludeKeys, boolean allowDuplicating)
Copies dictionary to specified document.PdfDictionary
copyTo(PdfDocument document, java.util.List<PdfName> excludeKeys, boolean allowDuplicating, ICopyFilter copyFilter)
Copies dictionary to specified document.java.util.Set<java.util.Map.Entry<PdfName,PdfObject>>
entrySet()
Returns a Set holding the key-value pairs as Map#Entry objects.PdfObject
get(PdfName key)
Returns the value associated to this key.PdfObject
get(PdfName key, boolean asDirect)
PdfArray
getAsArray(PdfName key)
Returns the value associated to this key as a PdfArray.java.lang.Boolean
getAsBool(PdfName key)
Returns the value associated to this key as a Boolean.PdfBoolean
getAsBoolean(PdfName key)
Returns the value associated to this key as a PdfBoolean.PdfDictionary
getAsDictionary(PdfName key)
Returns the value associated to this key as a PdfDictionary.java.lang.Float
getAsFloat(PdfName key)
Returns the value associated to this key as a Float.java.lang.Integer
getAsInt(PdfName key)
Returns the value associated to this key as an Integer.PdfName
getAsName(PdfName key)
Returns the value associated to this key as a PdfName.PdfNumber
getAsNumber(PdfName key)
Returns the value associated to this key as a PdfNumber.Rectangle
getAsRectangle(PdfName key)
Returns the value associated to this key as a Rectangle.PdfStream
getAsStream(PdfName key)
Returns the value associated to this key as a PdfStream.PdfString
getAsString(PdfName key)
Returns the value associated to this key as a PdfString.byte
getType()
Gets object type.boolean
isEmpty()
Returns true if there are no key-value pairs in this PdfDictionary.java.util.Set<PdfName>
keySet()
Returns all the keys of this PdfDictionary as a Set.void
mergeDifferent(PdfDictionary other)
This method merges different fields from two dictionaries into the current oneprotected PdfObject
newInstance()
Creates new instance of object.PdfObject
put(PdfName key, PdfObject value)
Inserts the value into this PdfDictionary and associates it with the specified key.void
putAll(PdfDictionary d)
Inserts all the key-value pairs into this PdfDictionary.protected void
releaseContent()
Release content of PdfDictionary.PdfObject
remove(PdfName key)
Removes the specified key from this PdfDictionary.int
size()
Returns the number of key-value pairs in this PdfDictionary.java.lang.String
toString()
java.util.Collection<PdfObject>
values()
Returns all the values of this map in a Collection.java.util.Collection<PdfObject>
values(boolean asDirects)
Returns all the values of this map in a Collection.-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObject
checkState, clearState, clone, clone, copyTo, copyTo, copyTo, copyTo, equalContent, flush, flush, getIndirectReference, isArray, isBoolean, isDictionary, isFlushed, isIndirect, isIndirectReference, isLiteral, isModified, isName, isNull, isNumber, isReleaseForbidden, isStream, isString, makeIndirect, makeIndirect, processCopying, processCopying, release, setIndirectReference, setModified, setState
-
-
-
-
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 overridevalue
- 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 containPdfIndirectReference
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 getPdfIndirectReference
instances for the indirect objects value, you shall usevalues(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 getPdfIndirectReference
instances for the indirect objects value, you shall useget(PdfName, boolean)
method.- Returns:
- a Set of Map.Entry objects
-
getType
public byte getType()
Description copied from class:PdfObject
Gets object type.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.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 UseNullCopyFilter
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 classPdfObject
- Returns:
- new instance of object.
-
copyContent
protected void copyContent(PdfObject from, PdfDocument document)
Copies object content from object 'from'.- Overrides:
copyContent
in classPdfObject
- 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 classPdfObject
- Parameters:
from
- object to copy content from.document
- document to copy object to.copyFilter
-ICopyFilter
a filter that will apply on dictionaries and array UseNullCopyFilter
for no filtering
-
releaseContent
protected void releaseContent()
Release content of PdfDictionary.
-
-