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

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

Community Beginner ,
Feb 26, 2025 Feb 26, 2025

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.

TOPICS
How to , Scripting
4.6K
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

correct answers 1 Correct answer

Community Expert , Feb 27, 2025 Feb 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 illegalC
...
Translate
Community Expert ,
Feb 26, 2025 Feb 26, 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

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 ,
Feb 27, 2025 Feb 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.

 

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 Beginner ,
Feb 27, 2025 Feb 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.

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 ,
Feb 27, 2025 Feb 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?

 

RobertatIDTasker_0-1740699796222.png

 

But Acrobat still shows it?

 

RobertatIDTasker_1-1740699836172.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
Community Expert ,
Feb 27, 2025 Feb 27, 2025

@Riannon368885617n15 did you use my updated script? If it still gives an error, I need another sample document that gives the error.

- Mark

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 Beginner ,
Feb 27, 2025 Feb 27, 2025

Yes I replied above., the updated script was perfect! we are just testing the flipbook now. but they are working in reader which they didn't before. So your script has saved me a lot of time of re-doing hyperlinks! much appreciated.

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 ,
Feb 27, 2025 Feb 27, 2025

@Riannon368885617n15 great to hear!

 

(I see your other reply now but the forum software makes these threads very confusing to navigate! Grr.)

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 Beginner ,
Feb 27, 2025 Feb 27, 2025

100% the message threads are very confusing to navigate. But thanks again you are a life saver.

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
New Here ,
Sep 16, 2025 Sep 16, 2025

Found this script after having the same problem with hidden characters when copying URLs from an Excel list. Worked well! Thank you!

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 ,
Sep 16, 2025 Sep 16, 2025
LATEST

Great to hear!

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 ,
Feb 27, 2025 Feb 27, 2025

@Riannon368885617n15

 

How are you creating those Hyperlinks?

 

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 Beginner ,
Feb 27, 2025 Feb 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.

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 Beginner ,
Feb 27, 2025 Feb 27, 2025

Here is a sample set of the urls

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 Beginner ,
Feb 27, 2025 Feb 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.

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 ,
Feb 27, 2025 Feb 27, 2025

@Riannon368885617n15 

 

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

 

RobertatIDTasker_0-1740697203723.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
Community Beginner ,
Feb 27, 2025 Feb 27, 2025

as presumed by m1b these are shared urls copied from another document - so the links got broken. but looks like the script has solved my issue

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 ,
Feb 27, 2025 Feb 27, 2025

@Riannon368885617n15 

 

> Interesting thing is - the URL's work when in acrobat pro or viewing the pdf

 

Interesting! Are you sure they are going to the *full* URL? Maybe they are missing the part after the carriage return, ie. "&utm" etc. Or maybe in the process of generating the pdf hyperlinks it automatically removes illegal characters, but not in the other process.

- Mark

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 ,
Feb 27, 2025 Feb 27, 2025

Thank you @Riannon368885617n15 that's helpful. I've updated my script above to work with your sample document. The bad URLs had a carriage return or linefeed in them. Please try it out the revised script.

- Mark

 

P.S. After reading Robert's comment, I should add that yes most of your hyperlinks were broken, but I assumed that was because you made a quick demo document. I assume they use shared destinations in another document that we don't have so they are broken. When I run my script on your demo document it fixed exactly 8 URLs. I'm not sure if that's what you expected.

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 ,
Feb 27, 2025 Feb 27, 2025

But InDesign do not report invalid URLHyperlinks?

 

RobertatIDTasker_0-1740698295846.png

 

Or it works in JavaScript?

 

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 Beginner ,
Feb 27, 2025 Feb 27, 2025

Amazing. I have ran the updated script and it appears to be fixing all of the hyperlinks. Much appreciated. I am just getting out web developer to check one chapter that i ran the script on to see if it converts to the flip book correctly - and if all good then this script has solved our issue

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 ,
Feb 27, 2025 Feb 27, 2025
quote

[...] When I run my script on your demo document it fixed exactly 8 URLs. I'm not sure if that's what you expected.


By @m1b

 

8 are a "good ones" - there are 58 in total:

 

RobertatIDTasker_0-1740698452529.png

 

And I don't see a "direct" way to get to them?

 

But they still show in the Acrobat:

 

RobertatIDTasker_0-1740698852549.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
Community Expert ,
Feb 27, 2025 Feb 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?

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 ,
Feb 27, 2025 Feb 27, 2025

Brad @ Roaring Mouse 

 

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

 

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 ,
Feb 28, 2025 Feb 28, 2025

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

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