Skip to main content
Participating Frequently
July 18, 2025
Question

Adding a ToolTip for an Annotation

  • July 18, 2025
  • 2 replies
  • 170 views

I am using Acrobat c++ sdk to develop my plugin. 
I need to create a ToolTip for an annotation. What I found is , Probably tooltip is not present as of now for an annotation. Although for ToolButton it is present.

To Implement , I ceated another annotation just beside my actual annotation and populated my data in that.
Binded two functions : MouseEnter and MouseExit to create and destroy the newly tool tip created annotation.

What I am trying is to run a thread, detach it, and in that thread , delele the annotation after two seconds. 

void RemoveToolTipAnnot(PDAnnot annot)
{
    AVDoc doc = AVAppGetActiveDoc();  // My program crashes here stating cannot access this .

    PDDoc pdDoc = AVDocGetPDDoc(doc);
    int pages = PDDocGetNumPages(pdDoc);

    bool found = false;
    for (int i = 0; i < pages; i++)
    {
        PDPage page = PDDocAcquirePage(pdDoc, i);
      ..........
      ..........

and this is main calling fn.

 pdPageDel = AVPageViewGetPage(pageView);

ASFixedRect rect, newToolTipRect;
PDAnnotGetRect(annot, &rect);

newToolTipRect.left = rect.right + Int16ToFixed(10);
newToolTipRect.top = rect.top + Int16ToFixed(10);
newToolTipRect.right = newToolTipRect.left + Int16ToFixed(100);
newToolTipRect.bottom = newToolTipRect.top - Int16ToFixed(30);

 tooltipAnnotDel =
    PDPageCreateAnnot(pdPageDel, ASAtomFromString("FreeText"), &newToolTipRect);

CosDoc cosDoc = CosObjGetDoc(PDAnnotGetCosObj(tooltipAnnotDel));
CosObj annotDict = PDAnnotGetCosObj(tooltipAnnotDel);

// Set tooltip text

CosObj co = PDAnnotGetCosObj(annot);
ASTCount cb;


string val = "";
if (CosDictKnownKeyString(co, TTC::DK_TTC_State))
{
    try
    {
        val = CosStringValue(CosDictGetKeyString(co, TTC::DK_TTC_State), &cb);
    }
    catch (...) {}
}

string data = "Annot Position:";
string d1 = data + val;
const char* str = d1.c_str();
CosObj contentsStr = CosNewString(cosDoc, false, (const  char*)str, strlen(str));
CosDictPut(annotDict, ASAtomFromString("Contents"), contentsStr);

// Set default appearance (DA)
const char* da = "0 0 1 rg /Helv 10 Tf";
CosObj daStr = CosNewString(cosDoc, false, (const  char*)da, strlen(da));
CosDictPut(annotDict, ASAtomFromString("DA"), daStr);

// Set color
PDColorValueRec color;
color.space = PDDeviceRGB;
color.value[0] = FloatToASFixed(1.0);
color.value[1] = FloatToASFixed(1.0);
color.value[2] = FloatToASFixed(0.8);
PDAnnotSetColor(tooltipAnnotDel, &color);

// Optional: make sure it's visible
PDAnnotSetFlags(tooltipAnnotDel, 0);

PDPageAddAnnot(pdPageDel, -2, tooltipAnnotDel);
   
PDPageNotifyContentsDidChange(pdPageDel);


PDPageRelease(pdPageDel);
thread t1(RemoveToolTipAnnot,tooltipAnnotDel);
t1.detach();


What is happening here?


2 replies

Thom Parker
Community Expert
Community Expert
July 18, 2025

First, don't mess with threads in a plug-in. The plug-in environment is heavily controlled. It's not like a regular DLL. If you need something to run (sort of) asynchronously, use an Idle cycle. 

 

Next, Acrobat also uses another annot to implement the popup comment for an annot. They don't delete it, just hide and show it on mouse over operations. It's not a bad model. But if you really do want to timeout the tooltip, use the ::SetTimer() system function. 

 

BTW: I use Windows drawing functions for tooltips.  Register a draw procedure with Acrobat that is called anytime the screen needs redrawing. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
July 18, 2025

[Question moved to the Acrobat SDK forum]