Skip to main content
johnnyZ
Inspiring
April 20, 2023
Answered

Change Form Field from visible onscreen but doesn't printing with script to printablr

  • April 20, 2023
  • 3 replies
  • 1672 views

I have this script which changes the color of the text based on the data.

Now, my issue is that if the message appears onscreen, I don't want it to print the message, however, if the actual text is visible onscreen, I'd like it to print the text.  Ugh !!!

Here's my script so far.

var fn = this.getField("Patients_First_Name").valueAsString;
var mn = this.getField("Patients_Middle_Name").valueAsString;
var ln = this.getField("Patients_Last_Name").valueAsString;

if (!fn && !mn && !ln) {
    event.value = "This will automatically fill-in after you complete Page 2.";
    event.target.textColor = ["RGB", 175/255 , 102/255 , 74/255 ];
} else {
    if (fn && mn && ln)
        event.value = fn + " " + mn + " " + ln;
    else if (fn && !mn && ln)
        event.value = fn + " " + ln;
    else if (!fn && mn && ln)
        event.value = ln;
    else if (fn && mn && !ln)
        event.value = fn;
    else if (fn && !mn && !ln)
        event.value = fn;
    else if (!fn && !mn && ln)
        event.value = ln;
    else
        event.value = "";
	event.target.textColor = color.blue;
}
This topic has been closed for replies.
Correct answer Nesa Nurani

Add:

event.target.display = display.noPrint;

where you set message.

And add:

event.target.display = display.visible;

 under the line where you set color blue.

3 replies

Thom Parker
Community Expert
Community Expert
April 20, 2023

 

The "Ugh" thing cannot be done in this script alone.  What you are asking for is to display different text for printing, than on screen.  So, either the text has to be changed on print, which is a bad idea, or printing has to show something else entirely, which is a good idea. 

 

  The way to do this is to put another field over top of  this text field. Set this text field to only display on screen, and the new field to only display on print. Then set the value of the new field to Ugh when the message is displayed and blank when the caculated value is displayed. 

 

Here's a simplification of your script, with a method for displaying the Ugh. 

 

var fn = this.getField("Patients_First_Name").valueAsString;
var mn = this.getField("Patients_Middle_Name").valueAsString;
var ln = this.getField("Patients_Last_Name").valueAsString;
event.value = [fn,mn,ln].join(" ");

if (event.value == "") {
    event.value = "This will automatically fill-in after you complete Page 2.";
    event.target.textColor = ["RGB", 175/255 , 102/255 , 74/255 ];
    this.getField("UghField").value = "Ugh";
} else {
   event.target.textColor = color.blue;
   this.getField("UghField").value = "";
}

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
April 20, 2023

Why this "Ugh"? 

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
April 20, 2023

Add:

event.target.display = display.noPrint;

where you set message.

And add:

event.target.display = display.visible;

 under the line where you set color blue.

johnnyZ
johnnyZAuthor
Inspiring
April 20, 2023

Nesa,

You came to my rescue again.  Thank you !!!

Obviously, I'm just learning how to write scripts for Acrobat.

Bernd Alheit
Community Expert
Community Expert
April 20, 2023

You can change the property "display" of the field.