Skip to main content
Anantha Prabu G
Legend
November 7, 2024
Question

How to Find 13-Digit Numbers in tables and Create Hyperlinks in Grouped Items in Adobe InDesign?

  • November 7, 2024
  • 2 replies
  • 785 views

Dear All,

I need help with a task in Adobe InDesign. I have a document with 13-digit numbers inside tables, and these numbers are part of grouped items. I want to:

  1. Find all the 13-digit numbers in the document.
  2. Create hyperlinks for these numbers automatically.
  3. Ensure that the hyperlinks are applied correctly, even if the 13-digit numbers are part of grouped items (i.e., text frames or objects grouped together).

Could someone guide me on how to achieve this, possibly with a script or using GREP expressions? Any help would be greatly appreciated!
i tried Indesign javascript:

// InDesign JavaScript
var myDoc = app.activeDocument;
var myStory = myDoc.stories;
var urlPrefix = "https://www.librairesdelest.fr/livre/";

// Find 13-digit numbers
app.findGrepPreferences = null;
app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\b\\d{13}\\b";

var foundItems = myDoc.findGrep();

for (var i = 0; i < foundItems.length; i++) {
    var match = foundItems[i];
    var thirteenDigitNumber = match.contents;
    var fullURL = urlPrefix + thirteenDigitNumber;

    // Create the hyperlink
    var source = myDoc.hyperlinkTextSources.add(match);
    myDoc.hyperlinkURLDestinations.add(fullURL);
    myDoc.hyperlinks.add(source, myDoc.hyperlinkURLDestinations.item(-1));
}

// Clear GREP preferences
app.findGrepPreferences = null;
app.changeGrepPreferences = null;

alert("Hyperlinks added to all 13-digit numbers!");





 




This topic has been closed for replies.

2 replies

brian_p_dts
Community Expert
Community Expert
November 7, 2024

Something like this perhaps would get either the containing group of the match, or the match's parent textframe if no group is found. 

 

 

var getGorTF = function(match) { 
var par = match.parent;
var ftf = false;
var tf = undefined;
while(par.constructor.name !== "Application") { 
  if (par.constructor.name == "Group") {
      return par;
  }
  if (par.constructor.name == "TextFrame" && !ftf) {
      tf = par;
      ftf = true;
  } 
  par = par.parent;
}
return tf;
}

 

 

 

Robert at ID-Tasker
Legend
November 7, 2024

@brian_p_dts 

 

I think OP has a problem with texts in Cells not being part of the search result of the document?

 

brian_p_dts
Community Expert
Community Expert
November 7, 2024

I think he's saying that the pageitemsource is not working. That's because he is adding it to the same SelectedItem, whereas in the second code, 

sourcePageItem : selectedItem

should be 

sourcePageItem : getGorTF(match)

 

Of course, we would want to check if the func returns undefined 

Robert at ID-Tasker
Legend
November 7, 2024

I'm on my phone - what's the problem with your code? 

 

Anantha Prabu G
Legend
November 7, 2024

Hi Robert,
I have taking the @Laubender code from adobe forum then find 13 digit number using grep, it's works well.
Thanks @Laubender and @Robert at ID-Tasker 
code is below:

 

// "Adds" a hyperlink to a selected page item with some properties:

var doc = app.documents[0];
var selectedItem= app.selection[0];
var urlDestString =  "https://www.librairesdelest.fr/livre/";

// Find 13-digit numbers
app.findGrepPreferences = null;
app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\b\\d{13}\\b";

var foundItems = doc.findGrep();

for (var i = 0; i < foundItems.length; i++) {
    var match = foundItems[i];
    var thirteenDigitNumber = match.contents;
    }

app.documents[0].hyperlinks.add
(
	{
		source : doc.hyperlinkPageItemSources.add
		( 
			{ 
				sourcePageItem : selectedItem
			} 
		) ,
		
		destination : doc.hyperlinkURLDestinations.add
		( 
			urlDestString +thirteenDigitNumber
		) ,
		
		borderStyle : HyperlinkAppearanceStyle.SOLID ,
		hidden : false ,
		highlight : HyperlinkAppearanceHighlight.INVERT
	}
);

 

 

Thanks,PrabuDesign smarter, faster, and bolder with InDesign scripting.
Robert at ID-Tasker
Legend
November 7, 2024

I'm not JS guy but I'm not sure how the last version can work for you - for all found results? 

 

You have a closing "}" for the loop too early in your code - so your code will only work for the selection?