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

Script to Extract hyperlinks from Indesign File with Page number

Participant ,
Feb 12, 2020 Feb 12, 2020

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

TOPICS
Scripting
7.4K
Translate
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

Community Expert , 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(
...
Translate
Community Expert ,
Feb 12, 2020 Feb 12, 2020

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

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

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

Translate
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
Community Expert ,
Feb 12, 2020 Feb 12, 2020

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

Translate
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
Community Expert ,
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(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

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

Hi, I need script to extract URLs from indesign files to notepad with page number on which url is located,

 

Translate
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
Community Expert ,
Nov 21, 2019 Nov 21, 2019

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. 

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

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

Translate
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
Community Expert ,
Nov 21, 2019 Nov 21, 2019

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 )

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

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

 

Capture.PNGexpand image

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

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

Translate
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
Community Expert ,
Nov 22, 2019 Nov 22, 2019

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 )

Translate
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
Enthusiast ,
Aug 17, 2022 Aug 17, 2022

@Manan Joshi 

 

Folder.myDocuments

 

Im Wondering if this folder path will work in both Windows and Mac ? and thank you

Best
Mohammad Hasanin
Translate
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
Community Expert ,
Aug 17, 2022 Aug 17, 2022

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

Translate
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
Enthusiast ,
Aug 17, 2022 Aug 17, 2022

Thanks @Manan Joshi 

Yes it Works in Windows too, Thank you again

Best
Mohammad Hasanin
Translate
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 ,
Jan 12, 2023 Jan 12, 2023

Is it possible to show links created via text anchors?

Translate
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
Community Expert ,
Jan 16, 2023 Jan 16, 2023

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

Translate
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 ,
Jan 16, 2023 Jan 16, 2023

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

Translate
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 ,
Jan 16, 2023 Jan 16, 2023

retagging @Manan Joshi 

Thank you for any insights you might have (regarding my question above).

Translate
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
Community Expert ,
Jan 16, 2023 Jan 16, 2023

Hi @Jennifer27951572g5uz,

I tried and it seems to work for me. See the video demonstration at the link below

https://youtu.be/Ohq-E5VShac

Let me know if I am missing something here. Sharing a sample document could also help

-Manan

 

Uploaded by Manan Joshi on 2023-01-17.
Translate
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 ,
Jun 05, 2023 Jun 05, 2023

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

Translate
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
Community Expert ,
Jun 05, 2023 Jun 05, 2023

It should be possible - as long as you don't modify your INDD document. 

 

Translate
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 ,
Nov 08, 2023 Nov 08, 2023

hi, it is not work for Indeign 2024?

 

Thanks

Translate
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
Community Expert ,
Mar 25, 2025 Mar 25, 2025

What do you get? Do you see an error or something. Please give more details.

-Manan

Translate
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
Community Expert ,
Mar 25, 2025 Mar 25, 2025

One thing I noticed is that the original code looks for hyperlinks starting with http. So if your hyperlink starts with something else like https, it would not work. You can check this aspect as well.

-Manan

Translate
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