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

Community Beginner ,
Oct 25, 2018

Copy link to clipboard

Copied

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?

Most Valuable Participant
Correct answer by Test Screen Name | Most Valuable Participant

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 .

TOPICS
Acrobat SDK and JavaScript

Views

304

Likes

Translate

Translate

Report

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

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

Community Beginner ,
Oct 25, 2018

Copy link to clipboard

Copied

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?

Most Valuable Participant
Correct answer by Test Screen Name | Most Valuable Participant

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 .

TOPICS
Acrobat SDK and JavaScript

Views

305

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 25, 2018 0
Adobe Community Professional ,
Oct 25, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 25, 2018 0
Community Beginner ,
Oct 26, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2018 0
Adobe Community Professional ,
Oct 26, 2018

Copy link to clipboard

Copied

Sorry, I don't have.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2018 0
Most Valuable Participant ,
Oct 26, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2018 0
Community Beginner ,
Oct 26, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2018 0
Most Valuable Participant ,
Oct 26, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2018 0
Community Beginner ,
Oct 26, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2018 0
Most Valuable Participant ,
Oct 26, 2018

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2018 0
Community Beginner ,
Oct 26, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2018 0
Most Valuable Participant ,
Oct 26, 2018

Copy link to clipboard

Copied

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 .

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2018 1
Community Beginner ,
Oct 26, 2018

Copy link to clipboard

Copied

Yes, that works. My revised code is then: (Note no color setting as the border has no width to color)

// 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);

_t_PDLinkAnnotBorder border;

PDLinkAnnotGetBorder(aLinkAnnot, &border);

border.width = 0;

PDLinkAnnotSetBorder(aLinkAnnot, &border);

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2018 0