Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Script to Extract hyperlinks from Indesign File with Page number

Explorer ,
Feb 12, 2020 Feb 12, 2020

Copy link to clipboard

Copied

Anyone have any script to extract hyperlinks from Indesign File with location (i.e with page number) 

TOPICS
Scripting

Views

1.6K

Likes

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

correct answers 1 Correct answer

Adobe Community Professional , Feb 12, 2020 Feb 12, 2020
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(...

Likes

Translate

Translate
Adobe Community Professional ,
Feb 12, 2020 Feb 12, 2020

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

https://community.adobe.com/t5/indesign/script-to-extract-url-from-indesign-file-to-txt-document-wit...

 

-Manan

Likes

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
Explorer ,
Feb 12, 2020 Feb 12, 2020

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();  

Likes

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
LEGEND ,
Feb 12, 2020 Feb 12, 2020

Copy link to clipboard

Copied

LATEST

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

Likes

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
Adobe Community Professional ,
Feb 12, 2020 Feb 12, 2020

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

Likes

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
Explorer ,
Nov 21, 2019 Nov 21, 2019

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,

 

Likes

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
Adobe Community Professional ,
Nov 21, 2019 Nov 21, 2019

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. 

Likes

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
Explorer ,
Nov 22, 2019 Nov 22, 2019

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

.Capture.PNG

Likes

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
Adobe Community Professional ,
Nov 21, 2019 Nov 21, 2019

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 )

Likes

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
Explorer ,
Nov 22, 2019 Nov 22, 2019

Copy link to clipboard

Copied

yes, they are visible in hyperlinks panel. and like below in file

 

Capture.PNG

Likes

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
Explorer ,
Nov 22, 2019 Nov 22, 2019

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();  

Likes

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
Adobe Community Professional ,
Nov 22, 2019 Nov 22, 2019

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 )

Likes

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