Creating highlight annotation
I need to create a menu item that creates a custom "Highlight Annotation" when selected. The user should be able to select some text and then press the menu item and a pop-up note should be displayed that has some static text in it plus the words that were highlighted. I have code that gets the text from the highlighted area, but I cannot create a proper highlight annotation. An annotation gets created but the text is not highlighted.
Here is my code snippet:
AVDoc avDoc = AVAppGetActiveDoc();
// if a PDF is open, get its number of pages
PDDoc pdDoc = AVDocGetPDDoc (avDoc);
ASFixedRect boundingRect;
char data[512] = "NEW NOTE";
int numPages = PDDocGetNumPages (pdDoc);
PDPage page = NULL;
PDAnnot annot,textannot;
// Get the selected text as a text select
PDTextSelect pdtext =
static_cast<PDTextSelect>(AVDocGetSelection(avDoc));
// Get the bounding box for the selection
PDTextSelectGetBoundingRect(pdtext, &boundingRect);
//Create a PDPage object
page = PDDocAcquirePage(pdDoc, 0);
//Create a PDAnnot object
annot = PDPageCreateAnnot (page, ASAtomFromString("HighLight"),&boundingRect);
//Cast the PDAnnot object to a PDTextAnnot object
textannot = CastToPDTextAnnot(annot);
//Open the annotation, set the text, and add it to a page
PDTextAnnotSetOpen (textannot,true);
strcat(data,textString);
PDTextAnnotSetContents (textannot, data, strlen (data));
PDPageAddAnnot(page,-2, textannot);
If I use the subtype of "Highlight" on the PDPageCreateAnnot call I get a strange icon and no popup box with the annotation.
If I use the subtype of "Text" on the PDPageCreateAnnot call I get a text icon at the start of the text string and a nice popup box with the annotation data.
The seems like it should be easy. I want to do the same thing that happens when I do a right mouse click on selected text and then click on "Add Note to Text (Comment)".
Please help!
Thank you in advance!
Navnath
