Skip to main content
Participating Frequently
October 25, 2018
Answered

C++ code to create text link to named destination?

  • October 25, 2018
  • 5 replies
  • 2810 views

I'm currently using rectangle links that clip into the text that I want the user to click.

Does anybody have c++ code for Acrobat Pro DC to

  1. Create a named destination to a page number that is currently valid, but allow the user to come in later insert pages in between and retain the destination.
  2. On a different page add what appears to be (and prints as) ordinary text but is actually a link to the named destination.

Failing that, how do I turn my rectangular link annotations invisible so they don't interfere with the link text?

This topic has been closed for replies.
Correct answer Test Screen Name

This turned out to need a lot more research than I was expecting, though this is fairly typical. I created two link annotations in the UI. One with a visible border and one without. The only difference was the visible one had /Border [0 0 1] while the invisible one had /Border [0 0 0]. This could be done with the Cos layer, but I believe the simplest API is likely to be PDLinkAnnotSetBorder .

5 replies

Inspiring
April 19, 2022

can you please send me the code for rectangular selection, i'm facing problem.

Legend
April 19, 2022

Why would you expect us to write your code for you?

Inspiring
May 5, 2022

Atleast explain the flow, How to select rectangular area/how to select text through arrow cursor.

 

I tried, Its not working.

Legend
October 26, 2018

Which API do you use at the moment? I ask because there are multiple overlapping APIs. Are you trying to use only the plugin guide or are you using the API Reference too?

hcobbAuthor
Participating Frequently
October 26, 2018

Here is the C++ code I am using currently to put a white rectangle around the link. Can I make it transparent instead?

  // Box around the link

  ASFixedRect initialRect;

  initialRect.left = ASInt32ToFixed(writeLeft);

  initialRect.top = ASInt32ToFixed(writeTop -5);

  initialRect.right = ASInt32ToFixed(endText +2);

  initialRect.bottom = ASInt32ToFixed(writeTop - lrint(1.5 * fontSize));

  PDPage gotoPage = PDDocAcquirePage(pdDoc, linkedPage);

  ASFixedRect destRect;

  PDPageGetCropBox(gotoPage,&destRect);

  PDViewDestination aViewDest=PDViewDestCreate(pdDoc,gotoPage,ASAtomFromString("XYZ"),&destRect,PDViewDestNULL,0);

  PDPageRelease(gotoPage);

  PDAction aAction= PDActionNewFromDest(pdDoc,aViewDest,pdDoc);

  PDAnnot aLinkAnnot = PDPageAddNewAnnot(pdPage, -2, ASAtomFromString("Link"), &initialRect);

PDLinkAnnotSetAction(aLinkAnnot, aAction);

PDColorValueRec colourWhite;

memset (& colourWhite, 0x00, sizeof (colourWhite));

colourWhite.space = PDDeviceRGB;

colourWhite.value [0] = fixedOne;

colourWhite.value [1] = fixedOne;

colourWhite.value [2] = fixedOne;

PDAnnotSetColor(aLinkAnnot, & colourWhite);

PDAnnotSetTitle(aLinkAnnot, linkText.c_str(), linkText.length());

PDEContentAddElem(pageContent, kPDEAfterLast, reinterpret_cast<PDEElement>(textObj));   

PDPageSetPDEContentCanRaise(pdPage, NULL);   //Set the content back into the page.

PDERelease(reinterpret_cast<PDEObject>(textObj)); // Done

Test Screen NameCorrect answer
Legend
October 26, 2018

This turned out to need a lot more research than I was expecting, though this is fairly typical. I created two link annotations in the UI. One with a visible border and one without. The only difference was the visible one had /Border [0 0 1] while the invisible one had /Border [0 0 0]. This could be done with the Cos layer, but I believe the simplest API is likely to be PDLinkAnnotSetBorder .

Legend
October 26, 2018

Please don’t ask for samples. Are you having trouble finding the info you want in the documentation?

hcobbAuthor
Participating Frequently
October 26, 2018

Yes, the documentation for link options is very sketchy.  It shows how to make a colored rectangle only.

Legend
October 26, 2018

Links /are/ ordinary text. Links are an overlay on the page.

hcobbAuthor
Participating Frequently
October 26, 2018

Do you have any sample C++ to create invisible links?

Bernd Alheit
Community Expert
Community Expert
October 26, 2018

1. you can create a plugin which adds the named destinations

hcobbAuthor
Participating Frequently
October 26, 2018

Yes, I am writing a plugin. Do you have any sample code that does this?

Bernd Alheit
Community Expert
Community Expert
October 26, 2018

Sorry, I don't have.