0

So far I implement a extension to export InDesign document to XML, everything work fine except the hyperlinks.

I can get all hyperlinks (HyperLinkURLDestination) via document.hyperlinkURLDestinations but there are no way to know which text in paragraph are linked to these hyperlinks. Any idea?

Leo
  • 1
  • 1

1 Answers1

0

An hyperlink has basically two properties, a source and a destination. The destination n your case is an url to be opened in the browser. However the source is actually an InDesign Text Object. Destinations can be used several times but sources only once per object. So I would recommend accessing text sources by the object actually using it i.e. a hyperlink.

var main = function() {
 var doc = app.properties.activeDocument,
 hlks,hlk,
 src,
 txt;
 
 if ( !doc) return;
 
 hlks = doc.hyperlinks;
 
 
 if ( !hlks.length ) return;
 
 hlk = hlks[0];
 src = hlk.source;
 
 if ( !( src instanceof HyperlinkTextSource) ) return;
 txt = src.sourceText;
 app.select ( txt );
 
 txt.parentTextFrames.length && zoomObject ( txt.parentTextFrames[0] );
 
 alert( "here you are…");
}


function zoomObject(theObj) {
 try {
  var objBounds = theObj.geometricBounds;
 } catch (e) {
  throw "Object doesn't have bounds."
 }
 var ObjHeight = objBounds[2] - objBounds[0];
 var ObjWidth = objBounds[3] - objBounds[1];
 var myWindow = app.activeWindow;
 var pageBounds = myWindow.activePage.bounds;
 var PgeHeight = pageBounds[2] - pageBounds[0];
 var PgeWidth = pageBounds[3] - pageBounds[1];
 var hRatio = PgeHeight/ObjHeight;
 var wRatio = PgeWidth/ObjWidth;
 var zoomRatio = Math.min(hRatio, wRatio);
 myWindow.zoom(ZoomOptions.fitPage);
 myWindow.zoomPercentage = myWindow.zoomPercentage * zoomRatio;
}

main();
Loic
  • 2,173
  • 10
  • 13