It is seldom confusing the form developer that, the prePrint logic executes even if the print was cancelled using xfa.event.cancelAction = true; It is also uncommon to see the postPrint logic is executing even after the print was cancelled.
Few tips to use the correct approach to prevent printing and handling postPrint event logic.
In general scenario, the form users are allowed to print only when there is no validation errors present in the form.
Consider the below code to prevent printing:
xfa.event.cancelAction = true;
app.alert("Don't execute this line if the print was cancelled!");
This works as expected as it will prevent showing the print dialog. However, any code writting after that will continue to execute. In this case, the alert will appear though the print was cancelled.
Nonethless, the postPrint event will also execute then. That means for each application event, there will be matching event that will occur regardless of cancelling the event.
Notice that the cancelAction is a property; rather than a method. This is helpful to check the property value to ensure if the print was cancelled or not.
The above code must be rewritten as follows to prevent any code execution if print is cancelled.
xfa.event.cancelAction = true;
if(xfa.event.cancelAction != true)
{
app.alert("Don't execute this line if the print was cancelled!");
}
The same condition can be checked on postPrint event to make sure that the code executes only when the print was not cancelled by the prePrint event.
I have attached two PDF files to show the difference.
Nith
+