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

Inserting line breaks within web addresses that Acrobat (Reader) recognizes them anyway

Participant ,
Apr 29, 2022 Apr 29, 2022

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":

mycc_0-1651238660892.png

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

 

 

TOPICS
Publish online , Scripting

Views

344

Translate

Translate

Report

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 ,
Apr 30, 2022 Apr 30, 2022

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

Votes

Translate

Translate

Report

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 ,
Apr 30, 2022 Apr 30, 2022

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

 

 

Screen Shot 2022-05-01 at 7.58.13 am.png

Votes

Translate

Translate

Report

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
Guide ,
Apr 30, 2022 Apr 30, 2022

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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