This example provides a generic solution that loops through a page and if all of the objects are null, then it will not print that page. If any of the objects have a value, then the page will be printed.
Again, this demonstrates the advantages of using a function (in a script object), which contains the main script. The function is called from the prePrint event of each page. Note that we are passing two variables into the function, which are both the same (eg page1). This is because if the page contains subforms we want to call the function recursively. When this happens the variables passed to the function will be the name of the subform and the original pageReference. This way we can still hide the page, respective of where the function is called from.
The script object and function are:
This would be called as:
If page1 contained a subform (eg called subform1), then the function could be automatically called recursively as:
Check out this example, which includes a screenshot explaining script objects and functions.
This example has been extended, so that it not does not test objects, whose name begins with DONOTTEST. See Revision 1 of the form, as linked below.