Q: How can I create custom annotations using PDFNet?
I am considering migrating from my current PDF library to PDFTron. The
objective of my operation is to programmaticaly insert two kinds of
items into existent PDF files.
(1) Fillable fields (text, radio buttons, check marks, etc.)
(2) Custom Annotation Types, more specifically custom links.
I have been doing part (1) for a while, and hence the question is
about part (2). I would like to know what is the PDFTron procedure to
insert such links.
Consider the attached files. The "Before" file is extremely simple,
it just
contains a phone number. I used a custom plugin to insert an invisible
link
into the file, on top of the phone number and the result is the
"After" file.
Notice how the cursor's shape changes when it hovers around the phone
number.
Question: Exactly what would I have to do with PDFTron in order to
convert the "Before" file into the "After" file?
----
A: Using PDFNet you can create custom annotations.
To create a custom annotation called 'phone' you could use the
following snippet:
// Assuming PDFNet v4 API:
Obj my_annot = pdfdoc.CreateIndirectDict();
my_annot.PutName("Subtype", "Phone");
my_annot.PutName("Type", "Annot");
my_annot.PutRect("Rect", 266, 116, 430, 204);
my_annot.PutBool("MyEntry", "1-800-3934-3093");
...
page.AnnotPushBack(new Annot(my_annot));
// in C++ use page.AnnotPushBack(Annot(my_annot));
-
Using CosEdit (
http://www.pdftron.com/cosedit) you can find the
relevant annotation dictionary using the following path: trailer/Root/
Pages/Kids/0/Annots/0