Defining variables using app.requires with closed choice of allowed values

The app.requires object can be used for two reasons:

To explicitly define dependencies in a Script variable from another variable. That should always be done when variables are used e.g. in Checsk or Fixups where it is important that a certain order is used when evaluation the variables.

The other more important use case is to define a variable within a JavaScript variable. This will be described in this article.

The example is variant of the "Viewing Distance related checks" Profile that you will find in pdfToolbox in the "Shapes, Variables, JavaScript, Place content" library.

The predefined Profile has a Profile level JavaScript variable that starts with

app.requires("input_viewingdistance",10,"Viewing distance [meter]");
app.requires("input_scalingfactor",100,"Scaling factor for PDF [%]");
Click to copy

The two app.requires calls define two variables, "input_viewingdistance" and "input_scalingfactor" , with default values (second parameter) and a label text that is used when the Profile is executed in pdfToolbox Desktop (third parameter).

With pdfToolbox 9.1 it is possible to define a list of possible values.

app.requires("input_viewingdistance",10,"Viewing distance [meter]",[10,12,14,18,20]);
Click to copy

If you want to only allow certain viewing distance values for a variable that is defined using app.requires you can use a fourth parameter that takes an array of values.

(For variables that are defined via the variable pop up you can do the same by using the "Limit input values to specific values" option.)