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

Change the text color of all links using JavaScript

New Here ,
Mar 06, 2023 Mar 06, 2023

Is there a way using JavaScript to change the text color of every link to blue?

TOPICS
JavaScript
1.1K
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 ,
Mar 06, 2023 Mar 06, 2023

Links don't have text (or text color) in PDF files. They are simply transparent boxes that exist above the text, so no, you can't do that. The only thing you can change about them is their border style (none, underline, dashed, etc.), width and color.

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 ,
Mar 06, 2023 Mar 06, 2023

Thanks,

That's what I was afraid of.

So, I'm trying to use the script below and underline every link in blue but I can't get the LineStyle syntax correct.
What is the correct syntax for that?

for (var p=0; p<this.numPages; p++) {
var box = this.getPageBox("Crop", p);
var links = this.getLinks(p, box);
if (links==null || links.length==0) continue;
for (var i in links) {
links[i].borderColor = color.blue;
links[i].borderWidth = 1;
links[i].LineStyle = "Underline";  
}
}

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 ,
Mar 06, 2023 Mar 06, 2023

Sorry, that's actually not editable using a script, unfortunately. I was thinking of button fields, not links.

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 ,
Mar 06, 2023 Mar 06, 2023
LATEST

If you can, I recommend converting your links to buttons. They work pretty much exactly the same, but buttons are much more customizable, including setting their text ("caption"), text color, border style, etc.

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