- java.lang.Object
-
- com.itextpdf.text.pdf.PdfObject
-
- com.itextpdf.text.pdf.PdfDictionary
-
- Direct Known Subclasses:
PdfAcroForm,PdfAction,PdfAnnotation,PdfBorderDictionary,PdfCollection,PdfCollectionField,PdfCollectionItem,PdfCollectionSchema,PdfCollectionSort,PdfDocument.PdfInfo,PdfFileSpecification,PdfGState,PdfLayer,PdfLayerMembership,PdfMediaClipData,PdfOCProperties,PdfOutline,PdfPage,PdfRendition,PdfShadingPattern,PdfSignature,PdfStream,PdfStructureElement,PdfStructureTreeRoot,PdfTargetDictionary,PdfTransparencyGroup,PRAcroForm
public class PdfDictionary extends PdfObject
PdfDictionaryis 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 ofPdfObject, 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
Fields Modifier and Type Field Description static PdfNameCATALOGThis is a possible type of dictionarystatic PdfNameFONTThis is a possible type of dictionaryprotected java.util.HashMaphashMapThis is the hashmap that contains all the values and keys of the dictionarystatic PdfNameOUTLINESThis is a possible type of dictionarystatic PdfNamePAGEThis is a possible type of dictionarystatic PdfNamePAGESThis is a possible type of dictionary
-
Constructor Summary
Constructors Constructor Description PdfDictionary()Constructs an emptyPdfDictionary-object.PdfDictionary(PdfName type)Constructs aPdfDictionary-object of a certain type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(PdfName key)Returnstrueif thisPdfDictionarycontains a mapping for the specified key.PdfObjectget(PdfName key)Returns thePdfObjectassociated to the specified key.PdfArraygetAsArray(PdfName key)Returns aPdfObjectas aPdfArray, resolving indirect references.PdfBooleangetAsBoolean(PdfName key)Returns aPdfObjectas aPdfBoolean, resolving indirect references.PdfDictionarygetAsDict(PdfName key)Returns aPdfObjectas aPdfDictionary, resolving indirect references.PdfIndirectReferencegetAsIndirectObject(PdfName key)Returns aPdfObjectas aPdfIndirectReference.PdfNamegetAsName(PdfName key)Returns aPdfObjectas aPdfName, resolving indirect references.PdfNumbergetAsNumber(PdfName key)Returns aPdfObjectas aPdfNumber, resolving indirect references.PdfStreamgetAsStream(PdfName key)Returns aPdfObjectas aPdfStream, resolving indirect references.PdfStringgetAsString(PdfName key)Returns aPdfObjectas aPdfString, resolving indirect references.PdfObjectgetDirectObject(PdfName key)Returns thePdfObjectassociated to the specified key, resolving a possible indirect reference to a direct object.java.util.SetgetKeys()Get all keys that are set.booleanisCatalog()Checks if aDictionaryis of the type CATALOG.booleanisFont()Checks if aDictionaryis of the type FONT.booleanisOutlineTree()Checks if aDictionaryis of the type OUTLINES.booleanisPage()Checks if aDictionaryis of the type PAGE.booleanisPages()Checks if aDictionaryis of the type PAGES.voidmerge(PdfDictionary other)voidmergeDifferent(PdfDictionary other)voidput(PdfName key, PdfObject object)Associates the specifiedPdfObjectas value with the specifiedPdfNameas key in this map.voidputAll(PdfDictionary dic)Copies all of the mappings from the specifiedPdfDictionaryto thisPdfDictionary.voidputEx(PdfName key, PdfObject value)Associates the specifiedPdfObjectas value to the specifiedPdfNameas key in this map.voidremove(PdfName key)Removes aPdfObjectand its key from thePdfDictionary.intsize()Returns the number of key-value mappings in thisPdfDictionary.voidtoPdf(PdfWriter writer, java.io.OutputStream os)Writes the PDF representation of thisPdfDictionaryas an array ofbyteto the givenOutputStream.java.lang.StringtoString()Returns a string representation of thisPdfDictionary.-
Methods inherited from class com.itextpdf.text.pdf.PdfObject
canBeInObjStm, getBytes, getIndRef, isArray, isBoolean, isDictionary, isIndirect, isName, isNull, isNumber, isStream, isString, length, setContent, setIndRef, type
-
-
-
-
Field Detail
-
FONT
public static final PdfName FONT
This is a possible type of 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
-
CATALOG
public static final PdfName CATALOG
This is a possible type of dictionary
-
hashMap
protected java.util.HashMap hashMap
This is the hashmap that contains all the values and keys of the dictionary
-
-
Constructor Detail
-
PdfDictionary
public PdfDictionary()
Constructs an emptyPdfDictionary-object.
-
PdfDictionary
public PdfDictionary(PdfName type)
Constructs aPdfDictionary-object of a certain type.- Parameters:
type- aPdfName
-
-
Method Detail
-
toPdf
public void toPdf(PdfWriter writer, java.io.OutputStream os) throws java.io.IOException
Writes the PDF representation of thisPdfDictionaryas an array ofbyteto the givenOutputStream.
-
toString
public java.lang.String toString()
Returns a string representation of thisPdfDictionary. The string doesn't contain any of the content of this dictionary. Rather the string "dictionary" is returned, possibly followed by the type of thisPdfDictionary, if set.- Overrides:
toStringin classPdfObject- Returns:
- the string representation of this
PdfDictionary - See Also:
PdfObject.toString()
-
put
public void put(PdfName key, PdfObject object)
Associates the specifiedPdfObjectas value with the specifiedPdfNameas key in this map. If the map previously contained a mapping for this key, the old value is replaced. If the value isnullorPdfNullthe key is deleted.- Parameters:
key- aPdfNameobject- thePdfObjectto be associated with the key
-
putEx
public void putEx(PdfName key, PdfObject value)
Associates the specifiedPdfObjectas value to the specifiedPdfNameas key in this map. If the value is aPdfNull, it is treated just as any otherPdfObject. If the value isnullhowever nothing is done.- Parameters:
key- aPdfNamevalue- thePdfObjectto be associated to the key
-
putAll
public void putAll(PdfDictionary dic)
Copies all of the mappings from the specifiedPdfDictionaryto thisPdfDictionary. These mappings will replace any mappings previously contained in thisPdfDictionary.- Parameters:
dic- ThePdfDictionarywith the mappings to be copied over
-
remove
public void remove(PdfName key)
Removes aPdfObjectand its key from thePdfDictionary.- Parameters:
key- aPdfName
-
get
public PdfObject get(PdfName key)
Returns thePdfObjectassociated to the specified key.- Parameters:
key- aPdfName- Returns:
- the PdfObject previously associated to the key
-
getDirectObject
public PdfObject getDirectObject(PdfName key)
Returns thePdfObjectassociated to the specified key, resolving a possible indirect reference to a direct object. This method will never return aPdfIndirectReferenceobject.- Parameters:
key- A key for thePdfObjectto be returned- Returns:
- A direct
PdfObjectornull
-
getKeys
public java.util.Set getKeys()
Get all keys that are set.- Returns:
trueif it is, otherwisefalse.
-
size
public int size()
Returns the number of key-value mappings in thisPdfDictionary.- Returns:
- the number of key-value mappings in this
PdfDictionary.
-
contains
public boolean contains(PdfName key)
Returnstrueif thisPdfDictionarycontains a mapping for the specified key.- Returns:
trueif the key is set, otherwisefalse.
-
isFont
public boolean isFont()
Checks if aDictionaryis of the type FONT.- Returns:
trueif it is, otherwisefalse.
-
isPage
public boolean isPage()
Checks if aDictionaryis of the type PAGE.- Returns:
trueif it is, otherwisefalse.
-
isPages
public boolean isPages()
Checks if aDictionaryis of the type PAGES.- Returns:
trueif it is, otherwisefalse.
-
isCatalog
public boolean isCatalog()
Checks if aDictionaryis of the type CATALOG.- Returns:
trueif it is, otherwisefalse.
-
isOutlineTree
public boolean isOutlineTree()
Checks if aDictionaryis of the type OUTLINES.- Returns:
trueif it is, otherwisefalse.
-
merge
public void merge(PdfDictionary other)
-
mergeDifferent
public void mergeDifferent(PdfDictionary other)
-
getAsDict
public PdfDictionary getAsDict(PdfName key)
Returns aPdfObjectas aPdfDictionary, resolving indirect references. The object associated with thePdfNamegiven is retrieved and resolved to a direct object. If it is aPdfDictionary, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
key- APdfName- Returns:
- the associated
PdfDictionaryobject, ornull
-
getAsArray
public PdfArray getAsArray(PdfName key)
Returns aPdfObjectas aPdfArray, resolving indirect references. The object associated with thePdfNamegiven is retrieved and resolved to a direct object. If it is aPdfArray, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
key- APdfName- Returns:
- the associated
PdfArrayobject, ornull
-
getAsStream
public PdfStream getAsStream(PdfName key)
Returns aPdfObjectas aPdfStream, resolving indirect references. The object associated with thePdfNamegiven is retrieved and resolved to a direct object. If it is aPdfStream, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
key- APdfName- Returns:
- the associated
PdfStreamobject, ornull
-
getAsString
public PdfString getAsString(PdfName key)
Returns aPdfObjectas aPdfString, resolving indirect references. The object associated with thePdfNamegiven is retrieved and resolved to a direct object. If it is aPdfString, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
key- APdfName- Returns:
- the associated
PdfStringobject, ornull
-
getAsNumber
public PdfNumber getAsNumber(PdfName key)
Returns aPdfObjectas aPdfNumber, resolving indirect references. The object associated with thePdfNamegiven is retrieved and resolved to a direct object. If it is aPdfNumber, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
key- APdfName- Returns:
- the associated
PdfNumberobject, ornull
-
getAsName
public PdfName getAsName(PdfName key)
Returns aPdfObjectas aPdfName, resolving indirect references. The object associated with thePdfNamegiven is retrieved and resolved to a direct object. If it is aPdfName, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
key- APdfName- Returns:
- the associated
PdfNameobject, ornull
-
getAsBoolean
public PdfBoolean getAsBoolean(PdfName key)
Returns aPdfObjectas aPdfBoolean, resolving indirect references. The object associated with thePdfNamegiven is retrieved and resolved to a direct object. If it is aPdfBoolean, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
key- APdfName- Returns:
- the associated
PdfBooleanobject, ornull
-
getAsIndirectObject
public PdfIndirectReference getAsIndirectObject(PdfName key)
Returns aPdfObjectas aPdfIndirectReference. The object associated with thePdfNamegiven is retrieved If it is aPdfIndirectReference, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
key- APdfName- Returns:
- the associated
PdfIndirectReferenceobject, ornull
-
-