Package com.itextpdf.kernel.pdf
Class PdfDictionary
java.lang.Object
com.itextpdf.kernel.pdf.PdfObject
com.itextpdf.kernel.pdf.PdfDictionary
- Direct Known Subclasses:
-
PdfStream
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.
-
Field Summary
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
ConstructorDescriptionCreates a new PdfDictionary instance.PdfDictionary
(PdfDictionary dictionary) Creates a new PdfDictionary instance.PdfDictionary
(Map<PdfName, PdfObject> map) Creates a new PdfDictionary instance.PdfDictionary
(Set<Map.Entry<PdfName, PdfObject>> entrySet) Creates a new PdfDictionary instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all key-value pairs from this PdfDictionary.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'.copyTo
(PdfDocument document, List<PdfName> excludeKeys, boolean allowDuplicating) Copies dictionary to specified document.copyTo
(PdfDocument document, List<PdfName> excludeKeys, boolean allowDuplicating, ICopyFilter copyFilter) Copies dictionary to specified document.entrySet()
Returns a Set holding the key-value pairs as Map#Entry objects.Returns the value associated to this key.getAsArray
(PdfName key) Returns the value associated to this key as a PdfArray.Returns the value associated to this key as a Boolean.getAsBoolean
(PdfName key) Returns the value associated to this key as a PdfBoolean.getAsDictionary
(PdfName key) Returns the value associated to this key as a PdfDictionary.getAsFloat
(PdfName key) Returns the value associated to this key as a Float.Returns the value associated to this key as an Integer.Returns the value associated to this key as a PdfName.getAsNumber
(PdfName key) Returns the value associated to this key as a PdfNumber.getAsRectangle
(PdfName key) Returns the value associated to this key as a Rectangle.getAsStream
(PdfName key) Returns the value associated to this key as a PdfStream.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.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
Creates new instance of object.Inserts the value into this PdfDictionary and associates it with the specified key.void
Inserts all the key-value pairs into this PdfDictionary.protected void
Release content of PdfDictionary.Removes the specified key from this PdfDictionary.int
size()
Returns the number of key-value pairs in this PdfDictionary.toString()
values()
Returns all the values of this map in a Collection.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, flush, flush, getIndirectReference, isArray, isBoolean, isDictionary, isFlushed, isIndirect, isIndirectReference, isLiteral, isModified, isName, isNull, isNumber, isReleaseForbidden, isStream, isString, makeIndirect, makeIndirect, release, setIndirectReference, setModified, setState
-
Constructor Details
-
PdfDictionary
public PdfDictionary()Creates a new PdfDictionary instance. -
PdfDictionary
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
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
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 Details
-
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
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
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
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
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
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
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
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
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
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
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
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:
-
getAsFloat
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
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
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
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
Removes the specified key from this PdfDictionary.- Parameters:
-
key
- key to be removed - Returns:
- the removed value associated with the specified key
-
putAll
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
Returns all the keys of this PdfDictionary as a Set.- Returns:
- Set of keys
-
values
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
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
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
-
clone
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, 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, 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
- 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
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
Description copied from class:PdfObject
Creates new instance of object.- Specified by:
-
newInstance
in classPdfObject
- Returns:
- new instance of object.
-
copyContent
Copies object content from object 'from'.- Overrides:
-
copyContent
in classPdfObject
- Parameters:
-
from
- object to copy content from. -
document
- document to copy object to.
-
copyContent
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.
-