Copy link to clipboard
Copied
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:
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!");
Copy link to clipboard
Copied
I'm on my phone - what's the problem with your code?
Copy link to clipboard
Copied
Hi Robert,
This code find 13 digit number and make hyperlink, but not pick the numbers in table.
Copy link to clipboard
Copied
You should get results from tables as well - can you post your screenshot again - but with Hidden Characters visible?
Copy link to clipboard
Copied
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
}
);
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Yes!! only selection, i am doing modify the all grouped items in document.
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
I think OP has a problem with texts in Cells not being part of the search result of the document?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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:
So I think something is wrong with the text in the Cells?
Copy link to clipboard
Copied
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more