Skip to main content
MD3D
Known Participant
July 23, 2018
Question

How to get the name of current selected destination?

  • July 23, 2018
  • 3 replies
  • 1092 views

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.

This topic has been closed for replies.

3 replies

Joel Geraci
Community Expert
Community Expert
July 24, 2018

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

MD3D
MD3DAuthor
Known Participant
July 25, 2018

the page will download the PDF.

Joel Geraci
Community Expert
Community Expert
July 25, 2018

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.

MD3D
MD3DAuthor
Known Participant
July 24, 2018

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.

try67
Community Expert
Community Expert
July 24, 2018

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...

MD3D
MD3DAuthor
Known Participant
July 24, 2018

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.

Thom Parker
Community Expert
Community Expert
July 23, 2018

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
July 23, 2018

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...