
Adobe Acrobat SDK
Working with Cos Objects
Developing Plug-ins and Applications
Creating Cos names 189
Creating Cos names
You can use the Acrobat core API to create a
CosObj
object that is based on a Cos name. To create a Cos
name, perform the following tasks:
1. Create a
CosDoc
object that represents a PDF file by invoking the
PDDocGetCosDoc
method and
passing a
PDDoc
object.
2. Create a
CosObj
object that represents the name by invoking the
CosNewName
method and passing
the following arguments:
●
A
CosDoc
object.
●
An
ASBool
object that specifies whether the
CosObj
object is an indirect or direct object. If
true
,
the string is an indirect object. If
false
, the string is a direct object. For information, see
“About
direct and indirect objects” on page 179
.
●
An
ASAtom
object that represent the name to create.
The
CosNewName
method returns a
CosObj
object that represents the new Cos name.
The following code example creates a Cos name with the value
Name1
. A
PDDoc
object named
myPDDoc
is passed to the
PDDocGetCosDoc
method. For information, see
“Creating a PDDoc object” on page 83
.
Example 17.8
Creating a Cos name
//Create a Cos name
CosObj nameObj;
CosDoc cd = PDDocGetCosDoc(myPDDoc);
nameObj = CosNewName(cd, false, ASAtomFromString("Name1"));
Retrieving the value of a name object
You can retrieve the value of a name object by using the Acrobat core API. For example, assume that you
retrieve the value from the Cos name object created in the previous code example. In this situation, the
value that is retrieved is
Name1
. To retrieve the value from a Cos name object, perform the following tasks:
1. Invoke the
CosNameValue
method and pass the
CosObj
that represents the Cos name. This method
returns an
ASAtom
object that represents the name value.
2. Invoke the
ASAtomGetString
method to get a constant character pointer that specifies the Cos
name value. Pass the
ASAtom
object that is returned from the
CosNameValue
method.
The following code example retrieves the value of a name object.
Example 17.9
Retrieving the value of a name object
//Create a Cos name
CosObj nameObj;
CosDoc cd = PDDocGetCosDoc(myPDDoc);
nameObj = CosNewName (cd, false, ASAtomFromString ("Name1"));
//Get and display the value of a Cos name object
ASAtom nameVal = CosNameValue(nameObj);
const char * str = ASAtomGetString(nameVal);
AVAlertNote(str);
Note:
The return value of the
ASAtomGetString
method is a constant character pointer, not a character
pointer. You will generate a compile error if you omit the
const
keyword.