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

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

Community Beginner ,
Feb 26, 2025 Feb 26, 2025

Copy link to clipboard

Copied

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

Views

409
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

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

Votes

Translate
Community Expert ,
Feb 26, 2025 Feb 26, 2025

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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.

 

Votes

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

Copy link to clipboard

Copied

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.

Votes

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

Copy link to clipboard

Copied

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

 

But Acrobat still shows it?

 

RobertatIDTasker_1-1740699836172.pngexpand image

Votes

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

Copy link to clipboard

Copied

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

- Mark

Votes

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

Copy link to clipboard

Copied

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.

Votes

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

Copy link to clipboard

Copied

@Riannon368885617n15 great to hear!

 

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

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

@Riannon368885617n15

 

How are you creating those Hyperlinks?

 

Votes

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

Copy link to clipboard

Copied

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.

Votes

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

Copy link to clipboard

Copied

Here is a sample set of the urls

Votes

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

Copy link to clipboard

Copied

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.

Votes

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

Copy link to clipboard

Copied

@Riannon368885617n15 

 

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

 

RobertatIDTasker_0-1740697203723.pngexpand image

 

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

@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

Votes

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

Copy link to clipboard

Copied

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.

Votes

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

Copy link to clipboard

Copied

But InDesign do not report invalid URLHyperlinks?

 

RobertatIDTasker_0-1740698295846.pngexpand image

 

Or it works in JavaScript?

 

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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

 

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

 

But they still show in the Acrobat:

 

RobertatIDTasker_0-1740698852549.pngexpand image

 

Votes

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

Copy link to clipboard

Copied

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?

Votes

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

Copy link to clipboard

Copied

Brad @ Roaring Mouse 

 

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

 

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

LATEST
quote

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


By Brad Roaring Mouse

 

Yeah. Yesterday I got a notification about messages posted 4 DAYS ago?? 

 

Or about posts that I don't follow?? 

 

Votes

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

Copy link to clipboard

Copied

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

 

RobertatIDTasker_0-1740699346305.pngexpand image

 

I get:

RobertatIDTasker_1-1740699380665.pngexpand image

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

 

RobertatIDTasker_2-1740699412497.pngexpand image

 

Goes to:

 

RobertatIDTasker_3-1740699452605.pngexpand image

 

 

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

 

Votes

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