Step by step - Learn how to use callas productscallas pdfToolbox Variables and JavaScriptHow to branch processing in a Process Plan using JavaScript

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) in the desktop version of pdfToolbox.

Executing the Process Plan will create a log as shown below:

2016-12-22 17:30:15 Branch on script result
2016-12-22 17:30:15 Input /Volumes/Work/PDFs/blank.pdf
2016-12-22 17:30:15 Starting with step1
2016-12-22 17:30:15 [1-1] cropbox smaller than 100pt
2016-12-22 17:30:15 Var cropbox smaller than 100pt 0
2016-12-22 17:30:15 Result Failure
2016-12-22 17:30:15 Continuing with step 3
2016-12-22 17:30:15 [2-3] error
2016-12-22 17:30:15 Var cropbox smaller than 100pt 0
2016-12-22 17:30:15 Var error Crop box is not smaller than 100pt
2016-12-22 17:30:15 Var message Crop box is not smaller than 100pt
2016-12-22 17:30:15 Result Success
2016-12-22 17:30:15 Terminating

0 Comments

Send Your Comment

E-Mail me when someone replies to this comment