Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Creating highlight annotation

New Here ,
Jan 13, 2017 Jan 13, 2017

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

TOPICS
Acrobat SDK and JavaScript
754
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 13, 2017 Jan 13, 2017
LATEST

Each annotation type has its own specific keys and requirements. If I had to do this I'd research in two ways.

1. add a highlight to a very small PDF and examine exactly what was added;

2. Refer to the PDF specification to see what each of the keys used means.

You may need to use the Cos layer to add keys not managed by the PDAnnot methods.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines