
Adobe Acrobat SDK
Working with Cos Objects
Developing Plug-ins and Applications
Retrieving the string value 184
Retrieving the string value
You can retrieve the string value from a
CosObj
that is based on a Cos string. To retrieve the string value,
invoke the
CosStringValue
method and pass the following arguments:
●
A
CosObj
that is based on a Cos string.
●
The address of an
ASTCount
object that is used to store the string length.
An exception is thrown if the
CosObj
object that is passed to the
CosStringValue
method is not based
on a Cos string. The following code example expands the previous code example by retrieving the string
value by invoking the
PDDocGetCosDoc
method.
Example 17.2
Retrieving the string value from a CosDoc object
//Create a new Cos string
char* mystr = "New String";
CosDoc cd = PDDocGetCosDoc (myPDDoc);
CosObj strObj = CosNewString(cd,false,mystr,strlen(mystr));
//Retrieve the string value
char* strValue;
ASTCount length;
strValue = CosStringValue(strObj, &length);
//Display the string value
AVAlertNote(strValue);
Working with Cos arrays
This section discusses ways in which you can work with Cos arrays.
Creating Cos arrays
You can use the Acrobat core API to create a
CosObj
object that is based on a Cos array. You specify the
number of elements that the Cos array stores when you create it. However, you can add elements
dynamically as needed. For example, assume that you create a Cos array that stores three elements. If
required, you can add a fourth element. An exception is thrown if the
CosObj
object that is added to the
Cos array is a direct object that is already located in another Cos collection object.
To create a Cos array, 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 is based on a Cos array by invoking the
CosNewArray
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
ASTArraySize
object that specifies the number of elements.