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

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

Engaged ,
Nov 07, 2024 Nov 07, 2024

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!");





AnanthaPrabuG_0-1730987702157.png

 




Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
TOPICS
Scripting
945
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
LEGEND ,
Nov 07, 2024 Nov 07, 2024

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

 

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
Engaged ,
Nov 07, 2024 Nov 07, 2024

Hi Robert,
This code find 13 digit number and make hyperlink, but not pick the numbers in table.

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
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
LEGEND ,
Nov 07, 2024 Nov 07, 2024

You should get results from tables as well - can you post your screenshot again - but with Hidden Characters visible?

 

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
Engaged ,
Nov 07, 2024 Nov 07, 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,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
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
LEGEND ,
Nov 07, 2024 Nov 07, 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? 

 

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
Engaged ,
Nov 07, 2024 Nov 07, 2024

Yes!! only selection, i am doing modify the all grouped items in document.

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
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 07, 2024 Nov 07, 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;
}

 

 

 

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
LEGEND ,
Nov 07, 2024 Nov 07, 2024

@brian_p_dts 

 

I think OP has a problem with texts in Cells not being part of the search result of the 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
Community Expert ,
Nov 07, 2024 Nov 07, 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 

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
LEGEND ,
Nov 07, 2024 Nov 07, 2024

@brian_p_dts 

 

First version of the code was working on:

    var source = myDoc.hyperlinkTextSources.add(match);

the latest on:

		source : doc.hyperlinkPageItemSources.add

 

but as per the earlier post:

RobertatIDTasker_0-1731000370489.png

 

So I think something is wrong with the text in the Cells?

 

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
LEGEND ,
Nov 07, 2024 Nov 07, 2024
LATEST

RobertatIDTasker_0-1731000676116.png

 

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