• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to get the name of current selected destination?

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

628

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
community guidelines
Community Expert ,
Jul 23, 2018 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();

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Expert ,
Jul 23, 2018 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...

Votes

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

Votes

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
community guidelines
Community Expert ,
Jul 24, 2018 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...

Votes

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

Votes

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
community guidelines
Community Expert ,
Jul 24, 2018 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?

Votes

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
community guidelines
Community Beginner ,
Jul 24, 2018 Jul 24, 2018

Copy link to clipboard

Copied

the page will download the PDF.

Votes

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
community guidelines
Community Expert ,
Jul 24, 2018 Jul 24, 2018

Copy link to clipboard

Copied

LATEST

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.

Votes

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
community guidelines