Skip to main content
Participating Frequently
December 17, 2019
Question

Highlight Text Lines Based on Dropdown Selection

  • December 17, 2019
  • 2 replies
  • 4388 views

Hello, I've search to no avail. I want to highlight certain text lines on a pdf form if the user selects a particular option from a dropdown list on the form. The text I want to highlight is not text fields but just regular text in the document. Thanks!

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
December 17, 2019

One more note: be aware that this level of scripting will only work on PDF viewers that support markup annotation scripting.  Basically Acrobat Pro/Reader and a handfull of desktop viewers. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
December 17, 2019

I have Acrobat XI   11.0.23

 

Does this work? I can access the console but not sure how to assign the script to the highlighted annotation

Thom Parker
Community Expert
Community Expert
December 17, 2019

Yes this will work on your version of Acrobat. 

I think you might be mixing some things up. Let's take it one bit at a time.

 

First, This is the only code you need to run in the Console window. And it's two separate lines. 

 

selectedAnnots[0].hidden = true;
selectedAnnots[0].name = "HG1";

 

Run each one separately. The "selectedAnnots" property is a list of annotations that are currently selected. So be sure the highlight is selected. 

the first line hides the highlight. You can make it visible again by running this code in the console

 

selectedAnnots[0].hidden = false;

 

When you can make this work you are ready for the next phase. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
December 17, 2019

The easy way to do this is to place the highlight over the text, set it to be hidden, and then use a script on the dropdown to turn the visibility on and off. So there is a bit of a process to this.

Here's the setup:

1)Place Highlight Annot

2) Select Annot

3) Open Console Window

Find a video tutorial on the Console here: https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

4) Run this code in the console to set the name of the highlight, and make it hidden

selectedAnnots[0].hidden = false
selectedAnnots[0].name = "HG1"

 

Here the name is "HG1", but you could make it anything.

 

And there's the setup. Use this code to make the highlight visibile

 

this.getAnnot(page#, "HG1").hidden = true;

where page# is the actual page number.  

 

So the next step is to add this code to a dropdown script. 

You'll find what you need in the article here:

https://acrobatusers.com/tutorials/change_another_field

 

You can find much more info on list and dropdown fields here:

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
December 17, 2019

Thom, I watched the tutorial on the Console and I'm not sure how to "run the code in the console" or what you mean by make it hidden then make it visible. ?

Participating Frequently
December 17, 2019

I'm getting this in the Console when I enter the code you provided:

 

selectedAnnots[0].hidden = false selectedAnnots[0].name = "HG1" HG1 this.getAnnot(page#, "HG1").hidden = true; SyntaxError: illegal character 1:Console:Exec undefined