How to get the name of current selected destination?

Community Beginner ,
Jul 23, 2018

Copy link to clipboard

Copied

Hi, Masters

I created one html page which can open the pdf and go to the target destination, under the guidance of your masters here.

Now, I need to detect the name of the current selected destination,because some of the JS within that document need to know the current  selected destination in order to shown some guidance information to the user.

Is there any way that I can detect the current selected destination with JS? Or could there be any other way to let me know where I am in the current document?

Thanks.

TOPICS
Acrobat SDK and JavaScript

Views

196

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

How to get the name of current selected destination?

Community Beginner ,
Jul 23, 2018

Copy link to clipboard

Copied

Hi, Masters

I created one html page which can open the pdf and go to the target destination, under the guidance of your masters here.

Now, I need to detect the name of the current selected destination,because some of the JS within that document need to know the current  selected destination in order to shown some guidance information to the user.

Is there any way that I can detect the current selected destination with JS? Or could there be any other way to let me know where I am in the current document?

Thanks.

TOPICS
Acrobat SDK and JavaScript

Views

197

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
Jul 23, 2018 0
Adobe Community Professional ,
Jul 23, 2018

Copy link to clipboard

Copied

There is no way to know the name of the destination that was just selected. That type of history information does not exist in the Acrobat JavaScript model

However,there are a few document properties that indicate the current view. 

doc.pageNum

doc.zoom

You'll find more info here: https://www.pdfscripting.com/members/DocumentNavigation.cfm

but the best tool for finding the page location is

doc.viewState

run this code from the console window to get the full list of what's in this object.

doc.viewState.toSource();

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...
Jul 23, 2018 0
Most Valuable Participant ,
Jul 23, 2018

Copy link to clipboard

Copied

Even with all of that information you won't be able to know which NamedDest was selected, unless the names of all of them are known in advance so they can be executed and compared to the current state...

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...
Jul 23, 2018 0
Community Beginner ,
Jul 24, 2018

Copy link to clipboard

Copied

Thanks Thom and try67,

Thanks for your reply. I can get all the names of the destination in advance. I can get all the texts and their coordinates from the pdf document in advance. I also found that I can highlight the target area from my html page. But the problem is how to have the javascript learn which one is currently focused or highlighted.  Seems that's not easy, any further suggestion?

Thanks.

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...
Jul 24, 2018 0
Most Valuable Participant ,
Jul 24, 2018

Copy link to clipboard

Copied

Let's take a very simple situation. You have 10 named destinations in the file, called Dest1 to Dest10, each one pointing to a different page, but you don't know to which one. You're currently on page 5 and you want to find out which one of them points to that page (if at all). You can then use this code to do it:

var matchingNamedDest = null;

var targetPage = this.pageNum;

for (var i=1; i<=10; i++) {

    this.gotoNamedDest("Dest"+i);

    if (this.pageNum==targetPage) {
          matchingNamedDest = "Dest"+i;

          break;
    }

}

if (matchingNamedDest==null) app.alert("No match found.")

else app.alert("Match found: " + matchingNamedDest, 1);

Of course, if you have multiple Named Dests pointing to different spots on the same page it becomes much more complicated...

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...
Jul 24, 2018 0
Community Beginner ,
Jul 24, 2018

Copy link to clipboard

Copied

Thanks try67,

Unfortunately, it is true in my case that " multiple Named Dests pointing to different spots on the same page". Seems I need to find a way out...

Thanks anyway.

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...
Jul 24, 2018 0
Adobe Community Professional ,
Jul 24, 2018

Copy link to clipboard

Copied

Does the HTML page force the PDF to download then open or do you have it opening in a browser window?

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...
Jul 24, 2018 0
Community Beginner ,
Jul 24, 2018

Copy link to clipboard

Copied

the page will download the PDF.

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...
Jul 24, 2018 0
Adobe Community Professional ,
Jul 24, 2018

Copy link to clipboard

Copied

Ok - then what you need to do is modify the links in your HTML to download an FDF rather than the PDF. The FDF must then reference the PDF and execute a JavaScript after the document has been opened. Each link would go to a different FDF that runs a script to go to a different destination in the PDF... of course, you could automate the generation of the FDF based on parameters in the link. This is not a trivial task.

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...
Jul 24, 2018 0