Skip to main content
Participant
October 12, 2023
Question

Auto resize font with a default starting size

  • October 12, 2023
  • 1 reply
  • 427 views

Hi! I have this script to set a default size (12pt) for my field "Name" but have it resize when it reaches the character limit (28) I set. However it is not working. I entered the code into the 'Documents JavaScripts' panel. I can't tell what could be the issue here? Multiline is off but even with it on it doesn't work. 

var threshold = 28; // Change this to your desired threshold var standardFontSize = 12; // Change this to your desired standard font size function formatNameField(event) { var fieldValue = event.value; if (fieldValue.length > threshold) { event.target.textSize = 0; } else { event.target.textSize = standardFontSize; } } this.getField("Name").setAction("Format", formatNameField);

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
October 13, 2023

Why not just enter the code into the custom format event script?  Putting this code into a document script creates a redundancy.  In general, the "setAction" function is meant to be used by automation scripts, not document scripts. 

 

The script is setting the textSize to auto. This may or may not change the font size displayed to the user. Try it with a real value. 

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often