Debugging JavaScript Variables (9.1)

pdfToolbox provides features that are designed specifically to make debugging of Script Variables easier:

  • Console
  • Serialisation of pdfToolbox JavaScript objects
  • Variable values are listed when "Log Profile Execution" is active


The Console is available below the Script Editor if "Show evaluation result" in enabled.

It works in the same way as in other JavaScript editors.

Since JavaScript "snippets" may be used at various places in a Profile it is sometimes required to temporarily copy code from somewhere else into the first lines of the Script Variable you are currently working on to make sure that the Variable has the same information as when it will be used in the Profile context.

In the example above the check that would fill the app.doc.result.checks[0].hits array has to be manually performed before the code in this Variable can be debugged. Only then the variable "loc_triggerarray" has a meaningful value. It is printed to the Console via console.log using "pretty printing" with the optional parameters null,"\t".

Serialisation of pdfToolbox JavaScript objects

In order to access information in any of the pdfToolbox JavaScript objects you may need to visualise the structure of these sometimes complex objects. The most complex object is the app object since that is the parent object for all other more specific objects.

This and all other pdfToolbox JavaScript objects can be serialised by the JSON.stringify function, if used with the optional parameters null,"\t" they are formatted nicely.

This screenshot shows parts of the app object after that has been output via console.log(JSON.stringify(app,null,"\t")) and copied from the Console into the Sublime editor. The part above shows the app.doc.result.checks part with hits and their trigger values.

Variable values listed in a logfile created via Log Profile Execution

If you are using Script Variables in a Process Plan you may need to know how Variable values are changed throughout processing. You enable logging via the options menu in the pdfToolbox main window.

If switched on a logfolder will be created that amongst other things includes a log file "process.log". The other contents of this folder are explained in further detail in a different article of this documentation:

All Variables that are stored in app.vars so that they are available throughout a Process Plan are listed for each of the steps of the Process Plan with their current values.

This screenshot shows that the variable "hitarray" had two entries in step 3 and was empty in step 4. (The empty lines before, between and after these two steps have been added to make the example more readable.)


Send Your Comment

E-Mail me when someone replies to this comment