com.lowagie.text.pdf
public class: PdfDictionary [javadoc |
source]
java.lang.Object
com.lowagie.text.pdf.PdfObject
com.lowagie.text.pdf.PdfDictionary
Direct Known Subclasses:
PdfPage, PdfAction, PdfCollectionSchema, PdfAcroForm, PdfCollectionSort, PdfMediaClipData, PPKMS, PdfCatalog, PdfSignature, PdfBorderDictionary, PdfOutline, PdfImage, PPKLite, PdfSigGenericPKCS, PdfFormField, PdfStructureElement, PdfOCProperties, PdfRendition, PdfStream, PdfCollection, PdfStructureTreeRoot, PdfGState, PdfContents, StreamFont, PdfFormXObject, PdfLayerMembership, PdfLayer, PdfFileSpecification, PdfTargetDictionary, PdfEFStream, VeriSign, PdfTrailer, PdfPattern, PdfCollectionField, PdfInfo, PdfTransparencyGroup, PdfICCBased, PdfResources, PdfCollectionItem, PdfAnnotation, PdfShadingPattern, PRAcroForm, PRStream
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).
| Field Summary |
|---|
| public static final PdfName | FONT | This is a possible type of dictionary |
| public static final PdfName | OUTLINES | This is a possible type of dictionary |
| public static final PdfName | PAGE | This is a possible type of dictionary |
| public static final PdfName | PAGES | This is a possible type of dictionary |
| public static final PdfName | CATALOG | This is a possible type of dictionary |
| protected HashMap | hashMap | This is the hashmap that contains all the values and keys of the dictionary |
| Fields inherited from com.lowagie.text.pdf.PdfObject: |
|---|
| BOOLEAN, NUMBER, STRING, NAME, ARRAY, DICTIONARY, STREAM, NULL, INDIRECT, NOTHING, TEXT_PDFDOCENCODING, TEXT_UNICODE, bytes, type, indRef |
| Method from com.lowagie.text.pdf.PdfDictionary Summary: |
|---|
|
contains, get, getAsArray, getAsBoolean, getAsDict, getAsIndirectObject, getAsName, getAsNumber, getAsStream, getAsString, getDirectObject, getKeys, isCatalog, isFont, isOutlineTree, isPage, isPages, merge, mergeDifferent, put, putAll, putEx, remove, size, toPdf, toString |
| Methods from com.lowagie.text.pdf.PdfObject: |
|---|
|
canBeInObjStm, getBytes, getIndRef, isArray, isBoolean, isDictionary, isIndirect, isName, isNull, isNumber, isStream, isString, length, setContent, setIndRef, toPdf, toString, type |
| Method from com.lowagie.text.pdf.PdfDictionary Detail: |
public boolean contains(PdfName key) {
return hashMap.containsKey(key);
}
|
public PdfObject get(PdfName key) {
return (PdfObject) hashMap.get(key);
}
Gets a PdfObject with a certain key from the PdfDictionary. |
public PdfArray getAsArray(PdfName key) {
PdfArray array = null;
PdfObject orig = getDirectObject(key);
if (orig != null && orig.isArray())
array = (PdfArray) orig;
return array;
}
|
public PdfBoolean getAsBoolean(PdfName key) {
PdfBoolean bool = null;
PdfObject orig = getDirectObject(key);
if (orig != null && orig.isBoolean())
bool = (PdfBoolean)orig;
return bool;
}
|
public PdfDictionary getAsDict(PdfName key) {
PdfDictionary dict = null;
PdfObject orig = getDirectObject(key);
if (orig != null && orig.isDictionary())
dict = (PdfDictionary) orig;
return dict;
}
All the getAs functions will return either null, or the specified object type
This function will automatically look up indirect references. There's one obvious
exception, the one that will only return an indirect reference. All direct objects
come back as a null.
Mark A Storer (2/17/06) |
public PdfIndirectReference getAsIndirectObject(PdfName key) {
PdfIndirectReference ref = null;
PdfObject orig = get(key); // not getDirect this time.
if (orig != null && orig.isIndirect())
ref = (PdfIndirectReference) orig;
return ref;
}
|
public PdfName getAsName(PdfName key) {
PdfName name = null;
PdfObject orig = getDirectObject(key);
if (orig != null && orig.isName())
name = (PdfName) orig;
return name;
}
|
public PdfNumber getAsNumber(PdfName key) {
PdfNumber number = null;
PdfObject orig = getDirectObject(key);
if (orig != null && orig.isNumber())
number = (PdfNumber) orig;
return number;
}
|
public PdfStream getAsStream(PdfName key) {
PdfStream stream = null;
PdfObject orig = getDirectObject(key);
if (orig != null && orig.isStream())
stream = (PdfStream) orig;
return stream;
}
|
public PdfString getAsString(PdfName key) {
PdfString string = null;
PdfObject orig = getDirectObject(key);
if (orig != null && orig.isString())
string = (PdfString) orig;
return string;
}
|
public PdfObject getDirectObject(PdfName key) {
return PdfReader.getPdfObject(get(key));
}
This function behaves the same as 'get', but will never return an indirect reference,
it will always look such references up and return the actual object. |
public Set getKeys() {
return hashMap.keySet();
}
|
public boolean isCatalog() {
return CATALOG.equals(dictionaryType);
}
Checks if a Dictionary is of the type CATALOG. |
public boolean isFont() {
return FONT.equals(dictionaryType);
}
Checks if a Dictionary is of the type FONT. |
public boolean isOutlineTree() {
return OUTLINES.equals(dictionaryType);
}
Checks if a Dictionary is of the type OUTLINES. |
public boolean isPage() {
return PAGE.equals(dictionaryType);
}
Checks if a Dictionary is of the type PAGE. |
public boolean isPages() {
return PAGES.equals(dictionaryType);
}
Checks if a Dictionary is of the type PAGES. |
public void merge(PdfDictionary other) {
hashMap.putAll(other.hashMap);
}
|
public void mergeDifferent(PdfDictionary other) {
for (Iterator i = other.hashMap.keySet().iterator(); i.hasNext();) {
Object key = i.next();
if (!hashMap.containsKey(key)) {
hashMap.put(key, other.hashMap.get(key));
}
}
}
|
public void put(PdfName key,
PdfObject value) {
if (value == null || value.isNull())
hashMap.remove(key);
else
hashMap.put(key, value);
}
Adds a PdfObject and its key to the PdfDictionary.
If the value is null or PdfNull the key is deleted. |
public void putAll(PdfDictionary dic) {
hashMap.putAll(dic.hashMap);
}
|
public void putEx(PdfName key,
PdfObject value) {
if (value == null)
return;
put(key, value);
}
Adds a PdfObject and its key to the PdfDictionary.
If the value is null it does nothing. |
public void remove(PdfName key) {
hashMap.remove(key);
}
Removes a PdfObject and its key from the PdfDictionary. |
public int size() {
return hashMap.size();
}
|
public void toPdf(PdfWriter writer,
OutputStream os) throws IOException {
os.write('< ");
os.write('< ");
// loop over all the object-pairs in the HashMap
PdfName key;
PdfObject value;
int type = 0;
for (Iterator i = hashMap.keySet().iterator(); i.hasNext(); ) {
key = (PdfName) i.next();
value = (PdfObject) hashMap.get(key);
key.toPdf(writer, os);
type = value.type();
if (type != PdfObject.ARRAY && type != PdfObject.DICTIONARY && type != PdfObject.NAME && type != PdfObject.STRING)
os.write(' ");
value.toPdf(writer, os);
}
os.write(' >");
os.write(' >");
}
Returns the PDF representation of this PdfDictionary. |
public String toString() {
if (get(PdfName.TYPE) == null) return "Dictionary";
return "Dictionary of type: " + get(PdfName.TYPE);
}
|