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.
1 Correct answer
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
...
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
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.
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.
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.
By Riannon368885617n15
There is no "direct" access to non-working Hyperlinks.
You can't even edit it manually?
But Acrobat still shows it?
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
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.
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.)
Copy link to clipboard
Copied
100% the message threads are very confusing to navigate. But thanks again you are a life saver.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Here is a sample set of the urls
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
> 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
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.
Copy link to clipboard
Copied
But InDesign do not report invalid URLHyperlinks?
Or it works in JavaScript?
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
Copy link to clipboard
Copied
[...] 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:
And I don't see a "direct" way to get to them?
But they still show in the Acrobat:
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?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I saw that after the fact.:) I get these messages out of order sometimes in my email. Fun times.
Copy link to clipboard
Copied
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??
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:
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


-
- 1
- 2