DL Logo

CosDict Functions

CosDictGet

Header: CosProcs.h:634

Description

Gets the value of the specified key in the specified dictionary. If it is called with a stream object instead of a dictionary object, this method gets the value of the specified key from the stream's attributes dictionary.

Note: Use CosObjEnum() to list all key-value pairs in a dictionary.

Syntax

CosObj CosDictGet(CosObj dict, ASAtom key);

Parameters

dict
The dictionary or stream from which a value is obtained.
key

The key whose value is obtained, repesented as an ASAtom. See the description of "Dictionary Objects" in ISO 32000-1:2008, Document Management-Portable Document Format-Part 1: PDF 1.7, section 7.3.7, page 18.

You can find this document on the web store of the International Standards Organization (ISO).

Here you will find the names of keys in dictionary objects that are part of standard PDF, such as annotations or page objects (for example, CosDictGet(dict, ASAtomFromString("Length"))).

Note that strings can be used directly as keys, by calling CosDictGetKeyString() (for example, CosDictGetKeyString(dict, "Length")). This method is preferred, because it avoids the creation of new ASAtom objects.

Key Names: Even though key names in a PDF file are written with a leading slash (e.g., < < /Length 42 > >), the slash is omitted when creating an ASAtom to be used as a key, or when using the string directly as a key, as in the examples above.

Cos name objects can also be used as keys, by calling CosDictGetKey(). This method will also avoid the creation of new ASAtom objects and is often more convenient than using ASAtom objects or strings.

Returns

The object associated with the specified key. If key is not present or if its value is NULL (which is equivalent), it returns a NULL Cos object (a Cos object of type CosNull.)

CosDictGetKey

Header: CosProcs.h:1920

Description

Gets the value of the specified key in the specified dictionary. For more details, see CosDictGet().

Syntax

CosObj CosDictGetKey(CosObj dict, CosObj key);

Parameters

dict
The dictionary or stream from which a value is obtained.
key
The key whose value is obtained, represented as a Cos name object.

Returns

The object associated with the specified key. If key is not present, it returns a NULL Cos object.

CosDictGetKeyString

Header: CosProcs.h:1984

Description

Gets the value of the specified key in the specified dictionary. For more details, see CosDictGet().

Related Methods

CosDictGet CosDictGetKey

Syntax

CosObj CosDictGetKeyString(CosObj dict, const char *key);

Parameters

dict
The dictionary or stream from which a value is obtained.
key
The key whose value is obtained, represented as a string.

Returns

The object associated with the specified key. If key is not present, returns a NULL Cos object.

CosDictIsWeakReference

Header: CosProcs.h:2087

Description

Gets the state of a weak reference. For details, see CosDictSetWeakReference().

Syntax

ASBool CosDictIsWeakReference(CosObj dict, const char *key);

Parameters

dict
A dictionary.
key
The name of a key.

Returns

Returns the value of the isWeak parameter in the most recent call to CosDictSetWeakReference() with these parameters, or false if there has been no such call.

CosDictKnown

Header: CosProcs.h:776

Description

Tests whether a specific key is found in the specified dictionary. Calling this method is equivalent to checking if the value returned from CosDictGet() is a NULL Cos object.

If it is called with a stream object instead of a dictionary object, this method tests whether the specified key is found in the stream's attributes dictionary.

Syntax

ASBool CosDictKnown(CosObj dict, ASAtom key);

Parameters

dict
The dictionary or stream in which to look for key.
key

The key to find. See the description of "Dictionary Objects" in ISO 32000-1:2008, Document Management-Portable Document Format-Part 1: PDF 1.7, section 7.3.7, page 18.

You can find this document on the web store of the International Standards Organization (ISO).

Here you will find the names of keys in dictionary objects that are part of standard PDF, such as annotations or page objects (see CosDictGet() for Key Names).

Note that strings can be used directly as keys, by calling CosDictKnownKeyString() (for example, CosDictKnownKeyString(dict, "Length")). This method is preferred, because it avoids the creation of new ASAtom objects.

Cos name objects can also be used as keys, by calling CosDictKnownKey(). This method will also avoid the creation of new ASAtom objects and is often more convenient than using ASAtom objects or strings.

Returns

true if the value of a key is known (exists and is not NULL) in dict, false otherwise.

CosDictKnownKey

Header: CosProcs.h:1936

Description

Tests whether a specific key is found in the specified dictionary. Calling this method is equivalent to checking if the value returned from CosDictGetKey() is a NULL Cos object. For more details, see CosDictKnown().

Syntax

ASBool CosDictKnownKey(CosObj dict, CosObj key);

Parameters

dict
The dictionary or stream in which to look for key.
key
The key to find, represented as a Cos name object.

Returns

true if the value of a key is known (exists and is not NULL) in dict, false otherwise.

CosDictKnownKeyString

Header: CosProcs.h:2000

Description

Tests whether a specific key is found in the specified dictionary. Calling this method is equivalent to checking if the value returned from CosDictGetKeyString() is a NULL Cos object. For more details, see CosDictKnown().

Syntax

ASBool CosDictKnownKeyString(CosObj dict, const char *key);

Parameters

dict
The dictionary or stream in which to look for key.
key
The key to find, represented as a string.

Returns

true if the value of a key is known (exists and is not NULL) in dict, false otherwise.

CosDictPut

Header: CosProcs.h:689

Description

Sets the value of a dictionary key, adding the key to the dictionary if it is not already present. Sets the PDDocNeedsSave flag (see PDDocSetFlags) of the dict object's CosDoc if dict is indirect or is a direct object with an indirect composite object at the root of its container chain.

This method can also be used with a stream object. In that case, the key-value pair is added to the stream's attributes dictionary.

It is not safe to call CosDictPut() during a call to CosObjEnum() on that same dictionary (for example, from within the callback procedure).

An exception is raised if val is a direct non-scalar object that is already contained in another dictionary, array, or stream, or if dict and val belong to different documents.

Note: A dictionary entry whose value is NULL is equivalent to an absent entry; using CosDictPut() to put a NULL value in a dictionary has the same effect as calling CosDictRemove() to remove it from the dictionary.

Syntax

void CosDictPut(CosObj dict, ASAtom key, CosObj val);

Parameters

dict
The dictionary or stream in which a value is set.
key

The key whose value is set, represented as an ASAtom. See the description of "Dictionary Objects" in ISO 32000-1:2008, Document Management-Portable Document Format-Part 1: PDF 1.7, section 7.3.7, page 18.

You can find this document on the web store of the International Standards Organization (ISO).

Here you will find the names of keys in dictionary objects that are part of standard PDF, such as annotations or page objects (see CosDictGet() for Key Names)

Note that strings can be used directly as keys, by calling CosDictPutKeyString() (for example, CosDictPutKeyString(dict, "Length", lenObj)). This method is preferred, because it avoids the creation of new ASAtom objects.

Cos name objects can also be used as keys, by calling CosDictPutKey(). This method will also avoid the creation of new ASAtom objects and is often more convenient than using ASAtom objects or strings.

val
The value to set.

CosDictPutKey

Header: CosProcs.h:1958

Description

Sets the value of a dictionary key, adding the key to the dictionary if it is not already present. For more details, see CosDictPut().

It is not safe to call CosDictPutKey() during a call to CosObjEnum() on that same dictionary (for example, from within the callback procedure)

An exception is raised if val is a direct non-scalar object that is already contained in another dictionary, array, or stream, or if dict and val belong to different documents.

Syntax

void CosDictPutKey(CosObj dict, CosObj key, CosObj val);

Parameters

dict
The dictionary or stream in which a value is set.
key
The key whose value is set, represented as a Cos name object.
val
The value to set.

CosDictPutKeyString

Header: CosProcs.h:2021

Description

Sets the value of a dictionary key, adding the key to the dictionary if it is not already present. For more details, see CosDictPut().

It is not safe to call CosDictPutKey() during a call to CosObjEnum() on that same dictionary (for example, from within the callback procedure).

An exception is raised if val is a direct non-scalar object that is already contained in another dictionary, array, or stream, or if dict and val belong to different documents.

Related Methods

CosDictPut CosDictPutKey

Syntax

void CosDictPutKeyString(CosObj dict, const char *key, CosObj val);

Parameters

dict
The dictionary or stream in which a value is set.
key
The key whose value is set, represented as a string.
val
The value to set.

CosDictRemove

Header: CosProcs.h:736

Description

Removes a key-value pair from a dictionary. Sets the PDDocNeedsSave flag (see PDDocSetFlags) of the dict object's CosDoc if the dictionary is indirect or has an indirect composite object at the root of its container chain.

If it is called with a stream object instead of a dictionary object, this method removes the value of the specified key from the stream's attributes dictionary.

It is not safe to call CosDictRemove() during a call to CosObjEnum() on that same dictionary (for example, from within the callback procedure).

If the key is not present in the dictionary, CosDictRemove() has no effect.

Syntax

void CosDictRemove(CosObj dict, ASAtom key);

Parameters

dict
The dictionary from which the key-value pair is removed.
key

The key to remove, represented as an ASAtom. See the description of "Dictionary Objects" in ISO 32000-1:2008, Document Management-Portable Document Format-Part 1: PDF 1.7, section 7.3.7, page 18.

You can find this document on the web store of the International Standards Organization (ISO).

Here you will find the names of keys in dictionary objects that are part of standard PDF, such as annotations or page objects (see CosDictGet() for Key Names).

Note that strings can be used directly as keys, by calling CosDictRemoveString() (for example, CosDictRemoveString(dict, "Length")). This method is preferred, because it avoids the creation of new ASAtom objects.

Cos name objects can also be used as keys, by calling CosDictRemoveKey(). This method will also avoid the creation of new ASAtom objects and is often more convenient than using ASAtom objects or strings.

CosDictRemoveKey

Header: CosProcs.h:1971

Description

Removes a key-value pair from a dictionary. For more details, see CosDictRemove().

Syntax

void CosDictRemoveKey(CosObj dict, CosObj key);

Parameters

dict
The dictionary from which the key-value pair is removed.
key
The key to remove, represented as a Cos name object.

CosDictRemoveKeyString

Header: CosProcs.h:2033

Description

Removes a key-value pair from a dictionary. For more details, see CosDictRemove().

Syntax

void CosDictRemoveKeyString(CosObj dict, const char *key);

Parameters

dict
The dictionary from which the key-value pair is removed.
key
The key to remove, represented as a string.

CosDictSetWeakReference

Header: CosProcs.h:2076

Description

Weak and strong references.

When a Cos document is saved in full-save mode, objects that are not accessible from the root of the document are destroyed. This process uses a mark-and-sweep garbage collector: the root is marked, and then every object to which it refers is marked, and so on. At the end of this marking phase, objects that are not marked are destroyed.

A so-called weak reference changes this policy: during the marking phase, a reference that has been declared to be weak will not be marked. For example, when a dictionary is marked, all its keys and values are normally also marked. But if a certain key has been set as a weak reference, then the corresponding value will not be marked. Consequently, if there are no other references to that value, it will be destroyed.

A so-called strong reference also changes this policy, but in the opposite direction. An object for which there is a strong reference will be marked (and therefore will not be garbage-collected), even if there is no path to the object from the root of the document, and even if a weak reference exists for it.

CosDictSetWeakReference() establishes or removes a weak reference from a dictionary.

Syntax

void CosDictSetWeakReference(CosObj dict, const char *key, ASBool isWeak);

Parameters

dict
The dictionary containing the weak reference.
key
The name of a key in the dictionary.
isWeak

If true, the object stored in dict under key at the time of every subsequent full-save garbage collection will not be marked as a component of the dictionary. If there is no other path to that object from the root of the document, then it will be garbage- collected (destroyed) by garbage collection.

It is not an error if there is no such value at the time of garbage collection or at the time of the call to this function.

If isWeak is false (the default condition), then there is no such behavior, and the value, if any, will be marked in the normal manner. The case where isWeak is specified as false is intended primarily to reverse the effect of a previous call in which isWeak was true.

CosNewDict

Header: CosProcs.h:283

Description

Creates a new dictionary.

For information on dictionary objects in standard PDF files, such as annotations or page objects, see the description of "Dictionary Objects" in ISO 32000-1:2008, Document Management-Portable Document Format-Part 1: PDF 1.7, section 7.3.7, page 18. You can find this document on the web store of the International Standards Organization (ISO).

Syntax

CosObj CosNewDict(CosDoc dP, ASBool indirect, ASTArraySize nEntries);

Parameters

dP
The document in which the dictionary is used.
indirect
If true, it creates the dictionary as an indirect Cos object, and sets the dP object's PDDocNeedsSave flag (see PDDocFlags). If false, it creates the dictionary as a direct object.
nEntries
The number of entries in the dictionary. This value is only a hint; Cos dictionaries grow dynamically as needed.

Returns

The newly created dictionary Cos object.