
Adobe Acrobat SDK
Creating Annotations
Developing Plug-ins and Applications
Creating text annotations 109
4. Create a
PDAnnot
object by invoking the
PDPageCreateAnnot
method and passing the following
arguments:
●
An
ASPage
object that represents the page that will contain the new annotation.
●
An
ASAtom
object that represents the annotation’s subtype. Because a text annotation is created,
specify
Text
as the annotation’s subtype. For information about an annotation’s subtype, see the
Acrobat and PDF Library API Reference
.
●
The address of the
ASFixedRect
object.
5. Cast the
PDAnnot
object to a
PDTextAnnot
object by invoking the
CastToPDTextAnnot
method.
This method requires a
PDAnnot
object and returns a
PDTextAnnot
object.
6. Open the text annotation by invoking the
PDTextAnnotSetOpen
method. Opening an annotation
enables you to set its content. This method requires a
PDTextAnnot
object and an
ASBool
value that
specifies
true
.
7. Set the text of the annotation by invoking the
PDTextAnnotSetContents
method and passing the
following arguments:
●
A
PDTextAnnot
object that represents the annotation for which text is set.
●
A character pointer that specifies the text to set.
●
An
ASInt32
object that specifies the length of the character pointer.
8. Add the text annotation to the page by invoking the
PDPageAddAnnot
method and passing the
following arguments:
●
An
ASPage
object that represents the page that will contain the new annotation.
●
An
ASInt32
object that specifies the index that controls where the annotation is added. The first
annotation in the array has an index of zero. Passing a value of -2 adds the annotation to the end of
the array.
●
A
PDTextAnnot
object that represents the annotation.
The following code example adds a text annotation to a PDF document page. In this code example, a
PDDoc
object named
myPDDoc
exists. For information, see
“Creating a PDDoc object” on page 83
.
Example 8.1
Creating text annotations
PDPage page = NULL;
PDAnnot annot,textannot;
char* ptr = "This is initial text";
//Create an ASFixed object and define its borders
ASFixedRect fr;
fr.left = ASInt32ToFixed(36);
fr.top = ASInt32ToFixed(792-36);
fr.right = ASInt32ToFixed(136);
fr.bottom = ASInt32ToFixed(792-136);
//Create an ASPage object
page = PDDocAcquirePage(myPDDoc, 0);
//Create an ASPage object
page = PDDocAcquirePage(myPDDoc, 0);