Copy link to clipboard
Copied
Anyone have any script to extract hyperlinks from Indesign File with location (i.e with page number)
Try the following
var list = [];
for (a=0; a<app.activeDocument.hyperlinks.length; a++)
{
try
{
d = app.activeDocument.hyperlinks[a].destination.destinationURL;
if (d.match(/^http/))
{
var b = app.activeDocument.hyperlinks[a].source
var page
if(b.constructor.name == "HyperlinkPageItemSource")
page = b.sourcePageItem.parentPage.name
else if(b.constructor.name == "HyperlinkTextSource")
page = b.sourceText.parentTextFrames[0].parentPage.name
$.writeln(
...
Copy link to clipboard
Copied
Hi Abhijeet,
This thread seems to be similar to the following thread by you. Any specific reason to open up a new thread? Did the solution provided by Uwe in the previous thread not work for you? You did not respond to his suggestions
-Manan
Copy link to clipboard
Copied
Sorry it dosen't work for me, I have zero knowledge regarding scripting, So I need a complete script which can provide the list of URL'S present in InDesign file in txt file along with page number.
I have below Script which Extract all hyperlinks from InDesign file in new .txt file.
var list = [];
for (a=0; a<app.activeDocument.hyperlinks.length; a++)
{
try {
d = app.activeDocument.hyperlinks[a].destination.destinationURL;
if (d.match(/^http/))
list.push (d);
} catch(_) {}
}
// show the list
alert ('All links:\r'+list.join('\r'));
// save the list as a file
listFile = new File(Folder.myDocuments+"/all_links.txt");
if (listFile.open("w"))
{
listFile.writeln(list.join('\n'));
listFile.close();
listFile.execute();
}
Copy link to clipboard
Copied
> ... I have zero knowledge regarding scripting, So I need a complete script which does [x, y, and z] ...
That explains why you have been asking for free scripts for the past three years. Any chance we can get paid by now?
Copy link to clipboard
Copied
Try the following
var list = [];
for (a=0; a<app.activeDocument.hyperlinks.length; a++)
{
try
{
d = app.activeDocument.hyperlinks[a].destination.destinationURL;
if (d.match(/^http/))
{
var b = app.activeDocument.hyperlinks[a].source
var page
if(b.constructor.name == "HyperlinkPageItemSource")
page = b.sourcePageItem.parentPage.name
else if(b.constructor.name == "HyperlinkTextSource")
page = b.sourceText.parentTextFrames[0].parentPage.name
$.writeln(page)
list.push ("Page Name " + page + " " + d);
}
} catch(_) {}
}
// show the list
alert ('All links:\r'+list.join('\r'));
// save the list as a file
listFile = new File(Folder.myDocuments+"/all_links.txt");
if (listFile.open("w"))
{
listFile.writeln(list.join('\n'));
listFile.close();
listFile.execute();
}
-Manan
Copy link to clipboard
Copied
Hi, I need script to extract URLs from indesign files to notepad with page number on which url is located,
Copy link to clipboard
Copied
Are you comfortable writing this script yourself, or do you need someone to do it for you? The page number is in the document.page[i].name field. The URL could be found through a GREP search on the text. Setting up the log file is relatively straightforward using File objects. If you need help writing the script, happy to do it for a nominal fee. Feel free to PM.
Copy link to clipboard
Copied
I have code which extract hyperlinks (urls) from indd file to notepad, but i need page number where that specific url is in the file.
var list = [];
for (a=0; a<app.activeDocument.hyperlinks.length; a++)
{
try {
d = app.activeDocument.hyperlinks[a].destination.destinationURL;
if (d.match(/^http/))
list.push (d);
} catch(_) {}
}
// show the list
alert ('All links:\r'+list.join('\r'));
// save the list as a file
listFile = new File(Folder.myDocuments+"/all_links.txt");
if (listFile.open("w"))
{
listFile.writeln(list.join('\n'));
listFile.close();
listFile.execute();
}
Below is the example how urls look like in file
.
Copy link to clipboard
Copied
Hi,
are the URLs all visible in the Hyperlinks panel?
Are there also buttons with gotoURLBehaviors that contain URLs you want to pick up?
Any text that contains URL like contents that is just plain text?
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
yes, they are visible in hyperlinks panel. and like below in file
Copy link to clipboard
Copied
I have below code to extract URLs (hyperlinks) from INDD file to notepad, but i need the page number where the specific urls is in file.
var list = [];
for (a=0; a<app.activeDocument.hyperlinks.length; a++)
{
try {
d = app.activeDocument.hyperlinks[a].destination.destinationURL;
if (d.match(/^http/))
list.push (d);
} catch(_) {}
}
// show the list
alert ('All links:\r'+list.join('\r'));
// save the list as a file
listFile = new File(Folder.myDocuments+"/all_links.txt");
if (listFile.open("w"))
{
listFile.writeln(list.join('\n'));
listFile.close();
listFile.execute();
}
Copy link to clipboard
Copied
Look into the property source of object Hyperlink.
That's the key to the position of an individual hyperlinkTextSource ( source.sourceText.parentTextFrames array ) and hyperlinkPageItemSource ( source.sourcePageItem ).
From that you could see into property parentPage.
If the text container or the page item is not e.g. on the pasteboard or in overset text, you should be able to retrieve parentPage.documentOffset which is the sequential number of the page within the document. Or parentPage.name .
DOM documentation:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Hyperlink.html#d1e112792
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#HyperlinkTextSource.html#d1e115526
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#HyperlinkPageItemSource.html#d1e114735
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Page.html
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Folder.myDocuments
Im Wondering if this folder path will work in both Windows and Mac ? and thank you
Copy link to clipboard
Copied
I work on a MAC so surely I would have tested and it would have worked. I see no reason why it should not work on WIN machine as well. Give it a try and let me know if it does not. However, it should be an easy fix that I am sure you will take care of.
-Manan
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Is it possible to show links created via text anchors?
Copy link to clipboard
Copied
Hi @lalaland_,
Try the following code
var list = [];
for (a=0; a<app.activeDocument.hyperlinks.length; a++)
{
try
{
d = app.activeDocument.hyperlinks[a].destination
if(d instanceof HyperlinkTextDestination)
list.push ("Text Anchor Name " + d.name);
durl = d.destinationURL;
if (durl.match(/^http/))
{
var b = app.activeDocument.hyperlinks[a].source
var page
if(b.constructor.name == "HyperlinkPageItemSource")
page = b.sourcePageItem.parentPage.name
else if(b.constructor.name == "HyperlinkTextSource")
page = b.sourceText.parentTextFrames[0].parentPage.name
$.writeln(page)
list.push ("Page Name " + page + " " + durl);
}
} catch(_) {}
}
// show the list
alert ('All links:\r'+list.join('\r'));
// save the list as a file
listFile = new File(Folder.myDocuments+"/all_links.txt");
if (listFile.open("w"))
{
listFile.writeln(list.join('\n'));
listFile.close();
listFile.execute();
}
-Manan
Copy link to clipboard
Copied
Thank you for this @mananjoshi ...AND a follow up question.
Context: I'm not a coder (at all!) but I was able to copy the above script you shared; make it a .js file; install it; and run it...but the window that pops up (where the urls are supposed to be listed) is blank.
Question: The hyperlinks I'm using are all in a table (that extends over multiple pages). Is there a modification I need to make to the script for it to work for tables?
Thank you
Copy link to clipboard
Copied
retagging @Manan Joshi
Thank you for any insights you might have (regarding my question above).
Copy link to clipboard
Copied
I tried and it seems to work for me. See the video demonstration at the link below
Let me know if I am missing something here. Sharing a sample document could also help
-Manan
Copy link to clipboard
Copied
Hello
After extracting the hyperlinks, modifying them in exce, for example, is there any way to export them back to InDesign in order to generate a new updated pdf?
Many thanks in advance
Copy link to clipboard
Copied
It should be possible - as long as you don't modify your INDD document.
Copy link to clipboard
Copied
hi, it is not work for Indeign 2024?
Thanks
Copy link to clipboard
Copied
@M.Hasanin said:
Folder.myDocuments
"Im Wondering if this folder path will work in both Windows and Mac ? "
Hi,
you can look up property myDocuments for object Folder in the DOM documentation.
Scroll down to the second list of properties:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Folder.html
On my Windows 10 machine it returns:
~/Documents
Also try this and see what folder opens in the file explorer:
Folder.myDocuments.execute();
Regards,
Uwe Laubender
( Adobe Community Professional )
Copy link to clipboard
Copied