Copy link to clipboard
Copied
Hi,
using ID latest version (Win).
How can I insert line breaks into web adresses like http://something.com/blabla/xyz.abc13.3/and-so-one in smaller columns to get a better look/style/... ā that Acrobat Reader recognizes these URLs anyway after converting the document in a PDF?
Tried it e.g. with "forced line breaks":
... but Acrobat / Reader does only recognice the incomplete first line.
And: I do not want to add a hyperlink to these adresses manually ā they are too many ...
Any solution?
Thanks!
mycc
Copy link to clipboard
Copied
Hi @mycc, I'm thinking that a script could solve this. What if script found all https web urls and automatically made them into hyperlinks but also inserted discretionary line breaks between every character of the text part? This would mean that the hyperlinks would work and they would break very close to the column edge and look neat. What do you think?
- Mark
Copy link to clipboard
Copied
I've written a quick script that does what I think you want. Let me know how it goes for you.
- Mark
/*
Make Hyperlinks From URLs
for Adobe Indesign 2022
by m1b
here: https://community.adobe.com/t5/indesign-discussions/inserting-line-breaks-within-web-addresses-that-acrobat-reader-recognizes-them-anyway/m-p/12912966
Script makes hyperlinks for any text in document that look like url
and also inserts zero width spaces between characters of the text
so that messy urls will break close to column edge
*/
function main() {
var doc = app.activeDocument;
// find all the URLs in document
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = 'https?://[^ \n\r]+';
// this will be a collection of texts
var found = doc.findGrep();
for (var i = found.length - 1; i >= 0; i--) {
var text = found[i],
url = text.contents;
// set up hyperlink
var hyperlinkSource = doc.hyperlinkTextSources.add(text),
hyperlinkDestination = doc.hyperlinkURLDestinations.add(url, { hidden: true }),
hyperlink = doc.hyperlinks.add(hyperlinkSource, hyperlinkDestination),
name = url,
counter = 2;
while (doc.hyperlinks.itemByName(name).isValid) {
name = url + ' ' + String(counter);
counter++;
}
hyperlink.name = name;
// add discretionary breaks (zero width spaces) to text
for (var j = text.insertionPoints.length - 1; j >= 0; j--)
text.insertionPoints[j].contents = '\u200B';
}
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Make Hyperlinks From URLs');
Copy link to clipboard
Copied
It's always the first line only that will be automatically linked by Acrobat / Acrobat Reader.
A half-way solution:
Open the hyperlink panel (Fenster > Interaktiv > Hyperlinks)
Select the URL and in the panel's menu choose the second entry (Neuer Hyperlink aus URL)
You will see the new hyperlink in the panel and Acrobat / A. Reader will link the whole text.
It doesn't matter if there are line breaks or not.
Fenja