Copy link to clipboard
Copied
Hello,
I have created a plugin to create a Annotation with sub type Highlight annotation.
Basically I created a custom menu "CreateAnnot" to highlight the text when I select the particular text.
Plugin creates a highlight annotation and displays a message box with the annotated text.
I will put the screenshot so that you will get clear idea.
In above image, while creating highlight annotation, I selected the middle line text and annotation created properly for that line.
However, It returns the highlighted text along-with below and upper line in the messagebox.
That means it returns whole paragraph.
I am not getting why this is happening.
Here is my code for getting the annotated text:
ACCB1 ASBool ACCB2 pdTextSelectEnumTextProc(void* procObj, PDFont font, ASFixed size, PDColorValue color, char* text, ASInt32 textLen)
{
char stringBuffer[200];
strcpy(stringBuffer, text);
ss << stringBuffer;
return true;
}
if (ASAtomFromString("Highlight") == PDAnnotGetSubtype(annot))
{
// Gets the annotation's rect
PDAnnotGetRect(annot, &boundingRect);
// Gets the text selection from the annotation's rect
PDTextSelect textSelect = PDDocCreateTextSelect(pdDoc, pageNum, &boundingRect);
// create a callback to get the text from highlighted bounding box
PDTextSelectEnumText(textSelect, ASCallbackCreateProto(PDTextSelectEnumTextProc, &pdTextSelectEnumTextProc), &annBuf);
MessageBox(NULL, ss.str().c_str(), NULL, NULL);
}
Please let me know where I am going wrong?
Thanks.
Copy link to clipboard
Copied
I guess the highlight box is too high. Notice how it reaches into the line above, so the bottom of the "j"and "g" are inside the highlight. The question of what is "inside" and "outside" a rectangle is complex for text, and likely to use the font bounding box. If the text is overset (boxes overlap) as it often is, the task is hopeless. Simply using the bounding box may not be enough.
Copy link to clipboard
Copied
So, What can I use instead of bounding box in this case?
Copy link to clipboard
Copied
You could try the quads. But there is really a philosophical problem. These highlight annotations are intended for human eye use, and they convey good information to humans. They aren't intended to preserve selection state for computer use. So far as I know, Acrobat has no option to "copy highlighted text" and this is why. If you want to use an annotation to preserve selected text, consider making it part of the annotation dictionary. You could also consider using fuzzy logic.
Copy link to clipboard
Copied
You would need to write some heuristics around how much of each glyph is included…