com.lowagie.text.pdf

Class PdfDictionary

public class PdfDictionary extends PdfObject

PdfDictionary is the Pdf dictionary object.

A dictionary is an associative table containing pairs of objects. The first element of each pair is called the key and the second element is called the value. Unlike dictionaries in the PostScript language, a key must be a PdfName. A value can be any kind of PdfObject, including a dictionary. A dictionary is generally used to collect and tie together the attributes of a complex object, with each key-value pair specifying the name and value of an attribute.
A dictionary is represented by two left angle brackets (<<), followed by a sequence of key-value pairs, followed by two right angle brackets (>>).
This object is described in the 'Portable Document Format Reference Manual version 1.7' section 3.2.6 (page 59-60).

See Also: PdfObject PdfName BadPdfFormatException

Field Summary
static PdfNameCATALOG
This is a possible type of dictionary
PdfNamedictionaryType
This is the type of this dictionary
static PdfNameFONT
This is a possible type of dictionary
protected HashMaphashMap
This is the hashmap that contains all the values and keys of the dictionary
static PdfNameOUTLINES
This is a possible type of dictionary
static PdfNamePAGE
This is a possible type of dictionary
static PdfNamePAGES
This is a possible type of dictionary
Constructor Summary
PdfDictionary()
Constructs an empty PdfDictionary-object.
PdfDictionary(PdfName type)
Constructs a PdfDictionary-object of a certain type.
Method Summary
booleancontains(PdfName key)
Returns true if this PdfDictionary contains a mapping for the specified key.
PdfObjectget(PdfName key)
Returns the PdfObject associated to the specified key.
PdfArraygetAsArray(PdfName key)
Returns a PdfObject as a PdfArray, resolving indirect references.
PdfBooleangetAsBoolean(PdfName key)
Returns a PdfObject as a PdfBoolean, resolving indirect references.
PdfDictionarygetAsDict(PdfName key)
Returns a PdfObject as a PdfDictionary, resolving indirect references.
PdfIndirectReferencegetAsIndirectObject(PdfName key)
Returns a PdfObject as a PdfIndirectReference.
PdfNamegetAsName(PdfName key)
Returns a PdfObject as a PdfName, resolving indirect references.
PdfNumbergetAsNumber(PdfName key)
Returns a PdfObject as a PdfNumber, resolving indirect references.
PdfStreamgetAsStream(PdfName key)
Returns a PdfObject as a PdfStream, resolving indirect references.
PdfStringgetAsString(PdfName key)
Returns a PdfObject as a PdfString, resolving indirect references.
PdfObjectgetDirectObject(PdfName key)
Returns the PdfObject associated to the specified key, resolving a possible indirect reference to a direct object.
SetgetKeys()
Get all keys that are set.
booleanisCatalog()
Checks if a Dictionary is of the type CATALOG.
booleanisFont()
Checks if a Dictionary is of the type FONT.
booleanisOutlineTree()
Checks if a Dictionary is of the type OUTLINES.
booleanisPage()
Checks if a Dictionary is of the type PAGE.
booleanisPages()
Checks if a Dictionary is of the type PAGES.
voidmerge(PdfDictionary other)
voidmergeDifferent(PdfDictionary other)
voidput(PdfName key, PdfObject object)
Associates the specified PdfObject as value with the specified PdfName as key in this map.
voidputAll(PdfDictionary dic)
Copies all of the mappings from the specified PdfDictionary to this PdfDictionary.
voidputEx(PdfName key, PdfObject value)
Associates the specified PdfObject as value to the specified PdfName as key in this map.
voidremove(PdfName key)
Removes a PdfObject and its key from the PdfDictionary.
intsize()
Returns the number of key-value mappings in this PdfDictionary.
voidtoPdf(PdfWriter writer, OutputStream os)
Writes the PDF representation of this PdfDictionary as an array of byte to the given OutputStream.
StringtoString()
Returns a string representation of this PdfDictionary.

Field Detail

CATALOG

public static final PdfName CATALOG
This is a possible type of dictionary

dictionaryType

private PdfName dictionaryType
This is the type of this dictionary

FONT

public static final PdfName FONT
This is a possible type of dictionary

hashMap

protected HashMap hashMap
This is the hashmap that contains all the values and keys of the dictionary

OUTLINES

public static final PdfName OUTLINES
This is a possible type of dictionary

PAGE

public static final PdfName PAGE
This is a possible type of dictionary

PAGES

public static final PdfName PAGES
This is a possible type of dictionary

Constructor Detail

PdfDictionary

public PdfDictionary()
Constructs an empty PdfDictionary-object.

PdfDictionary

public PdfDictionary(PdfName type)
Constructs a PdfDictionary-object of a certain type.

Parameters: type a PdfName

Method Detail

contains

public boolean contains(PdfName key)
Returns true if this PdfDictionary contains a mapping for the specified key.

Returns: true if the key is set, otherwise false.

get

public PdfObject get(PdfName key)
Returns the PdfObject associated to the specified key.

Parameters: key a PdfName

Returns: the PdfObject previously associated to the key

getAsArray

public PdfArray getAsArray(PdfName key)
Returns a PdfObject as a PdfArray, resolving indirect references. The object associated with the PdfName given is retrieved and resolved to a direct object. If it is a PdfArray, it is cast down and returned as such. Otherwise null is returned.

Parameters: key A PdfName

Returns: the associated PdfArray object, or null

getAsBoolean

public PdfBoolean getAsBoolean(PdfName key)
Returns a PdfObject as a PdfBoolean, resolving indirect references. The object associated with the PdfName given is retrieved and resolved to a direct object. If it is a PdfBoolean, it is cast down and returned as such. Otherwise null is returned.

Parameters: key A PdfName

Returns: the associated PdfBoolean object, or null

getAsDict

public PdfDictionary getAsDict(PdfName key)
Returns a PdfObject as a PdfDictionary, resolving indirect references. The object associated with the PdfName given is retrieved and resolved to a direct object. If it is a PdfDictionary, it is cast down and returned as such. Otherwise null is returned.

Parameters: key A PdfName

Returns: the associated PdfDictionary object, or null

getAsIndirectObject

public PdfIndirectReference getAsIndirectObject(PdfName key)
Returns a PdfObject as a PdfIndirectReference. The object associated with the PdfName given is retrieved If it is a PdfIndirectReference, it is cast down and returned as such. Otherwise null is returned.

Parameters: key A PdfName

Returns: the associated PdfIndirectReference object, or null

getAsName

public PdfName getAsName(PdfName key)
Returns a PdfObject as a PdfName, resolving indirect references. The object associated with the PdfName given is retrieved and resolved to a direct object. If it is a PdfName, it is cast down and returned as such. Otherwise null is returned.

Parameters: key A PdfName

Returns: the associated PdfName object, or null

getAsNumber

public PdfNumber getAsNumber(PdfName key)
Returns a PdfObject as a PdfNumber, resolving indirect references. The object associated with the PdfName given is retrieved and resolved to a direct object. If it is a PdfNumber, it is cast down and returned as such. Otherwise null is returned.

Parameters: key A PdfName

Returns: the associated PdfNumber object, or null

getAsStream

public PdfStream getAsStream(PdfName key)
Returns a PdfObject as a PdfStream, resolving indirect references. The object associated with the PdfName given is retrieved and resolved to a direct object. If it is a PdfStream, it is cast down and returned as such. Otherwise null is returned.

Parameters: key A PdfName

Returns: the associated PdfStream object, or null

getAsString

public PdfString getAsString(PdfName key)
Returns a PdfObject as a PdfString, resolving indirect references. The object associated with the PdfName given is retrieved and resolved to a direct object. If it is a PdfString, it is cast down and returned as such. Otherwise null is returned.

Parameters: key A PdfName

Returns: the associated PdfString object, or null

getDirectObject

public PdfObject getDirectObject(PdfName key)
Returns the PdfObject associated to the specified key, resolving a possible indirect reference to a direct object. This method will never return a PdfIndirectReference object.

Parameters: key A key for the PdfObject to be returned

Returns: A direct PdfObject or null

getKeys

public Set getKeys()
Get all keys that are set.

Returns: true if it is, otherwise false.

isCatalog

public boolean isCatalog()
Checks if a Dictionary is of the type CATALOG.

Returns: true if it is, otherwise false.

isFont

public boolean isFont()
Checks if a Dictionary is of the type FONT.

Returns: true if it is, otherwise false.

isOutlineTree

public boolean isOutlineTree()
Checks if a Dictionary is of the type OUTLINES.

Returns: true if it is, otherwise false.

isPage

public boolean isPage()
Checks if a Dictionary is of the type PAGE.

Returns: true if it is, otherwise false.

isPages

public boolean isPages()
Checks if a Dictionary is of the type PAGES.

Returns: true if it is, otherwise false.

merge

public void merge(PdfDictionary other)

mergeDifferent

public void mergeDifferent(PdfDictionary other)

put

public void put(PdfName key, PdfObject object)
Associates the specified PdfObject as value with the specified PdfName as key in this map. If the map previously contained a mapping for this key, the old value is replaced. If the value is null or PdfNull the key is deleted.

Parameters: key a PdfName object the PdfObject to be associated with the key

putAll

public void putAll(PdfDictionary dic)
Copies all of the mappings from the specified PdfDictionary to this PdfDictionary. These mappings will replace any mappings previously contained in this PdfDictionary.

Parameters: dic The PdfDictionary with the mappings to be copied over

putEx

public void putEx(PdfName key, PdfObject value)
Associates the specified PdfObject as value to the specified PdfName as key in this map. If the value is a PdfNull, it is treated just as any other PdfObject. If the value is null however nothing is done.

Parameters: key a PdfName value the PdfObject to be associated to the key

remove

public void remove(PdfName key)
Removes a PdfObject and its key from the PdfDictionary.

Parameters: key a PdfName

size

public int size()
Returns the number of key-value mappings in this PdfDictionary.

Returns: the number of key-value mappings in this PdfDictionary.

toPdf

public void toPdf(PdfWriter writer, OutputStream os)
Writes the PDF representation of this PdfDictionary as an array of byte to the given OutputStream.

Parameters: writer for backwards compatibility os the OutputStream to write the bytes to.

Throws: IOException

toString

public String toString()
Returns a string representation of this PdfDictionary. The string doesn't contain any of the content of this dictionary. Rather the string "dictionary" is returned, possibly followed by the type of this PdfDictionary, if set.

Returns: the string representation of this PdfDictionary

See Also: toString