Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

PDF form ONLY can be printed if the validation is correct - PLEASE HELP!

Avatar

Former Community Member
Hello,




I need that my PDF form
only can be printed if the validation is correct.


It's the Designer code:




-------- Form1.subform.myPrintButton::click - (JavaScript, client) ---------




if (...) {
// validations are OK




   xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 1, 0, 0, 0);




} else {




   // then not print!




}

--------------------------------------







If I establish the PDF's security in order that it couldn't be printed, the xfa.host.print sentence doesn't work.




I have been looking for at the Acrobat JavaScript Reference and I haven't found anything that solve this.




On the other hand,
app.hideToolbarButton and
app.hideMenuItem methods,
throws NotAllowedError, and I wouldn't like to have to ask every client that download the pdf that installs a *.js file to give them permissions to
hide/show the impression button .





Could I use the prePrint and postPrint events in order to cancel, or allow the form printing ?





It is really possible to offer to the user that the only way to print the PDF form will be from my custom print button?







Thanks a lot in advance!,



DaN

2 Replies

Avatar

Level 7
You cannot selectively allow printing.



One possibility is to have an invisible but printable field which you

hide completely if the form is complete. Otherwise it could say

"incomplete" in large or small letters or do whatever you think

suitable.



Aandi Inston

Avatar

Former Community Member
i found a super cool secret code to validate the whole form in one line of code!



F.execValidate();



so my print button is a normal button (not a print button)

with this code for onclick:



if(F.execValidate())

{

xfa.host.print(1, "0", (xfa.host.numPages - 1).toString(), 0, 1, 0, 0, 0);

}



easy as that!

IMPORTANT:

- unfortunatly it does not check if required fields are empty

- it only checks the "validation pattern" under Object > Value

- the "Error" box beside "validation pattern message" MUST be checked (if it is not checked, your validation errors will still popup, but the function will return true when it should be false - and therefore the print box will popup)