6 Replies Latest reply on Mar 24, 2010 11:21 AM by try67

    How to automatic encrypt documents with Acrobat 9 standard ?

    Thomas38

      Hello,

       

      I wont to encrypt documents automatically as soon as the document is saved using  a standard password.

      The following script is nearly working but I don't get it managed to pass the required argument which refers to the currently active document to the context of the trusted function.

       

      What I'm doing wrong ?

       

      Thanks,

      Tom

       

      /* Applying a Security Policy to a PDF Document */
      /* You need to create a security policy before running this script */
      /* Use "Advanced > Security > Manage Security Policies" menu */

       

      var ApplySecurity = app.trustedFunction(
      function (doc)
      {

        var oMyPolicy = null;
        var sPolicyName = "StandardPassword";

        app.beginPriv();

        // First, Get the ID of StandardPassword security policy
        var aPols = security.getSecurityPolicies();
        for(var i=0; i<aPols.length; i++)
        {
           if(aPols[i].name == sPolicyName)
           {
                oMyPolicy = aPols[i];
                break;
           }
        }

        if(oMyPolicy != null)
        {
           var rtn = doc.encryptUsingPolicy({oPolicy: oMyPolicy});

            if(rtn.errorCode != 0)
            {
                 // Print error message into JavaScript Debugger Console
                 console.println("Security Error: " + rtn.errorText);
            }
        }

        app.endPriv();

      });

      ApplySecurity(this);