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

Hyperlink to hyperlinkTextDestination in external document

New Here ,
Dec 21, 2009 Dec 21, 2009

Copy link to clipboard

Copied

I have an InDesign book (.indb) with one document for each chapter, plus one document for the table of contents.  I'm trying to automate the process of making a hyperlink from each item in the TOC to a hyperlinkTextDestination I've already added to each of the other documents.  This way, when I Export for Digital Editions, I have copy of my TOC with hyperlinks to each chapter.

My TOC is just a simple page with a textFrame, with each link on its own line, like this:

Chapter 1

Chapter 2

Chapter 3

...

Can anyone please describe how to do this in JavaScript?  Thanks in advance for any help.

TOPICS
Scripting

Views

1.9K

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
New Here ,
Dec 21, 2009 Dec 21, 2009

Copy link to clipboard

Copied

I was finally able to figure out the problem, and since I haven't been able to find anything on this specific topic elsewhere, I'll post it here for posterity.

The main problem was that my destination document was closed when I tried to create the hyperlink.  I stored the hyperlinkTextDestinations for each doc into an array so I could call them later, and then closed the document so the script could do other stuff.  Anyway, here are the code snippets pertinent to hyperlinking to external hyperlinkTextDestinations:


var mydocs = bookPath.getFiles('*.indd');  // Folder containing each chapter's document

var hyperlinkDestinations = new Array;


for (i=0; i<mydocs.length; i++){

  var thisDoc = app.open(mydocs);

  // Add hyperlink destinations

  var newDestination = thisDoc.hyperlinkTextDestinations.add(thisDoc.textFrames[0].insertionPoints[0]);
  hyperlinkDestinations.push(newDestination);

  thisDoc.close();

}


Then in my TOC document:


var tocdoc = app.activeDocument;

var toc = tocdoc.textFrames[0].paragraphs;

for (i=0; i<toc.length; i++) {

  // My TOC list is in the same order as my files are...

  var myHyperlinkTextSource = tocdoc.hyperlinkTextSources.add(toc);

  var tempDoc = app.open(mydocs); // Make sure doc is open before referencing hyperlinkTextDestination
  var myHyperlink =
tocdoc.hyperlinks.add(myHyperlinkTextSource, hyperlinkDestinations);
  tempDoc.close();
}

This isn't my exact code (I just copied out bits and pieces), so I haven't tested it.  If anyone knows a better way of doing this, feel free to chime in.

I've taken a pretty deep dive into InDesign scripting and this forum has been incredibly helpful, so I hope this pays it forward, at least a little.  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
People's Champ ,
Dec 20, 2010 Dec 20, 2010

Copy link to clipboard

Copied

LATEST

bcmartinez,

Thanks for posting this. It's almost exactly a year later to the day (weird!), and I've run into the identical issue you write about (here's the thread: http://forums.adobe.com/message/3353050#3353050) Hope your solution works for me as well...

Thanks,

Ariel

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