How to branch processing in a Process Plan using JavaScript
When using a "Variable" sequence step within a Process Plan, it is possible to branch depending on the result of the Variable.
This sample uses a "Variable" step in step 1, which continues processing with step 2 in the case of "Success" or jumps to step 3 in the case of an "Error".
To branch in a Process Plan using a variable, the variable or the script must return one the two following values:
"false" or "0" (Null): Failure
"true" or "1": Success
For example within the Variable used in step 1 {CropBox smaller than 100pt}:
if ( app.doc.pages[0].cropBox.right - app.doc.pages[0].cropBox.left < 100)
var result = 1;
else
var result = 0;
//return a value:
result
In order to try this out yourself, please execute the attached Process Plan "Branch_on_script_result.kfpx" with the activated "Log profile execution" option (in the fly out menu in the upper right of the Profiles/Checks/Fixups window) or within the "test mode" in the desktop version of pdfToolbox.
Executing the Process Plan will create a log as shown below:
2026-08-26 10:10:38 Branch on script result
2026-08-26 10:10:38 Input /Volumes/Work/PDFs/blank.pdf
2026-08-26 10:10:38 [1-1]: Branch on script result
2026-08-26 10:10:38 Step type: Process plan
2026-08-26 10:10:38 [2-1]: CropBox smaller than 100pt
2026-08-26 10:10:38 Step type: Variable
2026-08-26 10:10:38 SCRIPT CropBox smaller than 100pt 0ms
2026-08-26 10:10:38 Variables:
2026-08-26 10:10:38 CropBox smaller than 100pt 0
2026-08-26 10:10:38 Result Failure
2026-08-26 10:10:38 Duration (ms) 11
2026-08-26 10:10:38 Return code 3
2026-08-26 10:10:38 [3-2]: error
2026-08-26 10:10:38 Step type: Variable
2026-08-26 10:10:38 SCRIPT error 0ms
2026-08-26 10:10:38 Variables:
2026-08-26 10:10:38 CropBox smaller than 100pt 0
2026-08-26 10:10:38 error Crop box is not smaller than 100pt
2026-08-26 10:10:38 message Crop box is not smaller than 100pt
2026-08-26 10:10:38 Result Success
2026-08-26 10:10:38 Duration (ms) 12
2026-08-26 10:10:38 Return code 0
2026-08-26 10:10:39 Duration (ms) 70
2026-08-26 10:10:39 Return code 0
2026-08-26 10:10:39 Done
