Skip to main content
Participating Frequently
February 27, 2025
Answered

Update urls to remove hidden character in large document so they function correctly

  • February 27, 2025
  • 7 replies
  • 3653 views

I have a product catalogue that has hyperlinks applied to each product name so the respective webpage for the product will load if the product name is clicked when viewing the exported pdf.

 

Unfortunately the url's have a strange hidden character that isn't always visible - I have found "^p" sometimes when i copy and paste the url back and forth from notepad - so this may be the character I am looking for. But in acrobat pro when I go in the edit url menu there is a visible space that appears after the product number in the URL.

Does anyone know a script that I can run in either indesign or acrobat to search for the character in every single hyperlink in the document to remove the character, The document has several thousand hyperlinks so it's a very tedious job to do one by one.

Correct answer m1b

Hey @Riannon368885617n15, can you try this script and see if it works? It's a stab in the dark, but it might do the trick.

- Mark

 

 

/**
 * @file Clean Hyperlinks.js
 * 
 * Attempts to strip bad characters from
 * the active document's hyperlink URLs.
 * 
 * @author m1b
 * @version 2025-02-28
 * @discussion https://community.adobe.com/t5/indesign-discussions/update-urls-to-remove-hidden-character-in-large-document-so-they-function-correctly/m-p/15180488
 */
function main() {

    const illegalCharacters = /[\x00-\x1F\x7F-\x9F\u200B\u200C\u200D\n\r]+/g;

    var doc = app.activeDocument,
        hyperlinks = doc.hyperlinks,
        counter = 0;

    for (var i = 0; i < hyperlinks.length; i++) {

        var hyperlink = hyperlinks[i];

        try {
            if ('HyperlinkURLDestination' !== hyperlink.destination.constructor.name)
                continue;
        } catch (error) {
            // $.writeln('Hyperlink ' + i + ' links to a missing document.');
            continue;
        }

        // quick attempt to strip bad characters
        var originalURL = hyperlink.destination.destinationURL,
            newURL = originalURL.replace(illegalCharacters, '');

        if (newURL === originalURL)
            continue;

        // fix the hyperlink
        hyperlink.destination.destinationURL = newURL;
        counter++;

        // $.writeln('Fixed Hyperlink ' + i + ' URL: ' + hyperlink.destination.destinationURL)

    }

    alert('Cleaned ' + counter + ' hyperlink URLs.');

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Clean Hyperlinks');

Edit 2025-02-28: changed code a bit to work with OP's sample document.

 

7 replies

Robert at ID-Tasker
Legend
February 27, 2025

@Riannon368885617n15 

 

I think I know what's the problem - all your bad Hyperlinks point to:

 

P:\Marketing Communications\Literature\Pricelists\New Zealand\2025\February\2_Domestic &amp; Household_NZ.indd

 

m1b
Community Expert
Community Expert
February 27, 2025

Yes Robert, but it is only a sample document. On OP's machine they might be fine.

Robert at ID-Tasker
Legend
February 27, 2025

What's also interesting - if I'll click on DAB-102CORE - by the way - only "DAB-102" is an active hyperlink:

 

 

I get:

But the same link - is displayed in InDesign as correct:

 

 

Goes to:

 

 

 

Link when clicked in Acrobat:

 

https://www.whiteint.co.nz/page-not-found?r=%2fProductDisplay.aspx%3fProduct%3d808414%250D%26utm_source%3dLiterature%26utm_medium%3dProduct%2bGuide%26utm_campaign%3dNZ%2bItem%2bCode

 

But displays correctly in Acrobat - as shown above.

 

And InDesign:

 

https://www.whiteint.co.nz/ProductDisplay.aspx?Product=808414&utm_source=Literature&utm_medium=Product+Guide&utm_campaign=NZ+Item+Code

 

m1b
Community Expert
Community Expert
February 27, 2025

Yes that seems to be the problem—a carriage return in the URL. The encoded version you show from Acrobat has double-encoded the carriage return (the %250D). Normal (correct!) encoding is %0D, but if you encode that again the % is encoded as %25.

 

It is strange that the problem doesn't appear in the indesign one. I think the hyperlinks might be a bit messy.

Brad @ Roaring Mouse
Community Expert
Community Expert
February 27, 2025

What do the links that are problematoc look like on the page?

I'm wondering if an errant paragraph return (which is typically ^p) was inserted in one of your long hyperlinks to break tham in the layout?

Robert at ID-Tasker
Legend
February 27, 2025

@Brad @ Roaring Mouse 

 

Yes, that's in the 2nd paragraph of the OP's post 😉

 

Brad @ Roaring Mouse
Community Expert
Community Expert
February 28, 2025

I saw that after the fact.:)  I get these messages out of order sometimes in my email. Fun times.

Participating Frequently
February 27, 2025

Here is a sample set of the urls

Participating Frequently
February 27, 2025

Interesting thing is - the URL's work when in acrobat pro or viewing the pdf in any browser. But when we convert the pdf to an online flipbook, the urls dont work.

Robert at ID-Tasker
Legend
February 27, 2025

@Riannon368885617n15 

 

Most of your hyperlinks are not working - are incorrect - even in InDesign?

 

 

Robert at ID-Tasker
Legend
February 27, 2025

@Riannon368885617n15

 

How are you creating those Hyperlinks?

 

Participating Frequently
February 27, 2025

I was updating hyperlinks in notepad replacing the product code in the URL. unfortunatley as I was copying the code from the indesign table it looks like it brought over hidden characters/artifacts from the original excel spreadsheet the data came from.

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
February 27, 2025

Hey @Riannon368885617n15, can you try this script and see if it works? It's a stab in the dark, but it might do the trick.

- Mark

 

 

/**
 * @file Clean Hyperlinks.js
 * 
 * Attempts to strip bad characters from
 * the active document's hyperlink URLs.
 * 
 * @author m1b
 * @version 2025-02-28
 * @discussion https://community.adobe.com/t5/indesign-discussions/update-urls-to-remove-hidden-character-in-large-document-so-they-function-correctly/m-p/15180488
 */
function main() {

    const illegalCharacters = /[\x00-\x1F\x7F-\x9F\u200B\u200C\u200D\n\r]+/g;

    var doc = app.activeDocument,
        hyperlinks = doc.hyperlinks,
        counter = 0;

    for (var i = 0; i < hyperlinks.length; i++) {

        var hyperlink = hyperlinks[i];

        try {
            if ('HyperlinkURLDestination' !== hyperlink.destination.constructor.name)
                continue;
        } catch (error) {
            // $.writeln('Hyperlink ' + i + ' links to a missing document.');
            continue;
        }

        // quick attempt to strip bad characters
        var originalURL = hyperlink.destination.destinationURL,
            newURL = originalURL.replace(illegalCharacters, '');

        if (newURL === originalURL)
            continue;

        // fix the hyperlink
        hyperlink.destination.destinationURL = newURL;
        counter++;

        // $.writeln('Fixed Hyperlink ' + i + ' URL: ' + hyperlink.destination.destinationURL)

    }

    alert('Cleaned ' + counter + ' hyperlink URLs.');

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Clean Hyperlinks');

Edit 2025-02-28: changed code a bit to work with OP's sample document.

 

Participating Frequently
February 27, 2025

Do I need to edit anything in the javascript, it wouldn't work in my natuve document, but in the sample document I saved (below comments) it ran the scriupt but the characters were still present.

Robert at ID-Tasker
Legend
February 27, 2025
quote

Do I need to edit anything in the javascript, it wouldn't work in my natuve document, but in the sample document I saved (below comments) it ran the scriupt but the characters were still present.


By @Riannon368885617n15

 

There is no "direct" access to non-working Hyperlinks.

 

You can't even edit it manually?

 

 

But Acrobat still shows it?

 

m1b
Community Expert
Community Expert
February 27, 2025

Hi @Riannon368885617n15 this might be easy to fix with a script. Can you post a sample document with some of the problematic hyperlinks in it?

- Mark