Question
Protect PDF document with Javascript
How to password protect(take off) PDF document using Javascript code?
Pre-created a protection policy with the name "MySecurityPol", and run this code from the console in Acrobat Pro DC, but there is a syntax error! What am I doing wrong?
var DoApplyMySecurity = app.trustedFunction( function(){ var oMyPolicy = null; app.beginPriv(); // First, Get the ID of My Security Policy var aPols = security.getSecurityPolicies() for(var index=0;index<aPols.length;index++){ if(aPols[index].name == "MySecurityPol"){ oMyPolicy = aPols[index]; break; } } if(oMyPolicy == null){ app.alert("Policy Not Found"); return; } // Now, Apply the security Policy var rtn = this.encryptUsingPolicy({oPolicy: oMyPolicy }); if(rtn.errorCode != 0) app.alert("Security Error: " + rtn.errorText); app.endPriv(); });
I want to put a code in the form field to protect the document, when I click on the form, the code is launched and the document is encrypted.
