6 Replies Latest reply on Aug 17, 2011 3:34 PM by JoFrmOZ

    Digitally Sign All Signature Fields in the Active Document

    JoFrmOZ

      I have a script which will sign a single digital signature field by the field name.

       

      I need to revise the script so it will sign multiple/all signature fields in the active document without having to put the field name in the script, as the field names will vary with each document.

       

      Can anyone please advise how to modify the script to sign all fields in the active document regardless of the field name?

       

      function myOtherTrustedFunction()
      {
      app.beginPriv();
      // Get and login to security handler

      var oSigHdlr = security.getHandler( "Adobe.PPKLite" );
      oSigHdlr.login( "123","/c/Documents and Settings/name/Application Data/Adobe/Acrobat/10.0/Security/FirstNameLastName.pfx");

      // Setup Signing Properties

      var chk = this.getField("Checked");
      if (chk != null) {

      // Apply Signature and save back to original file

      var bRtn = chk.signatureSign({oSig:oSigHdlr, bUI:false, oInfo:{password:"123"}});
      }

      app.endPriv();
      }

       

      Any assistance will be most appreciated.

        • 1. Re: Digitally Sign All Signature Fields in the Active Document
          George_Johnson MVP & Adobe Community Professional

          If you don't know the field names in advance, you'll have to loop through all of the fields and test to see if the the current field's type property is equal to "signature". Also check to see if it's already signed by looking at its value.

           

          Here's some sample code for looping through the fields in a document: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.480.html

           

          The getNthFieldName method will give you the field name, which you can use with the getField method to get a field object.

          1 person found this helpful
          • 2. Re: Digitally Sign All Signature Fields in the Active Document
            JoFrmOZ Level 1

            Thank you for your assistance George.

             

            I have created the first part of the script which counts the number of signature fields - this works fine.

             

            The script is not working for the validation or value of the signature field, it is returning the total number of signature fields, not the number of signature fields which are blank (require signing).

             

            Can you please offer some advice as to why the validation is not working?

             

            var count = 0;
            for ( var i=0; i<this.numFields; i++) {
            var fname = this.getNthFieldName(i);
            var status = this.getField(fname).signatureValidate();

            if ( this.getField(fname).type == "signature" && status == 0) count++; }
            console.println("There are " + count + " Signature fields which require signing.");

            • 3. Re: Digitally Sign All Signature Fields in the Active Document
              George_Johnson MVP & Adobe Community Professional

              Try something like:

               

              var count = 0;
              
              for (var i = 0; i < numFields; i++) {
              
                  // Get the current field object
                  f = getField(getNthFieldName(i));
              
                  // If it's a signature field and not already signed, increment counter
                  if (f.type === "signature" && !f.value) {
                      count++;
                  }
              }
              
              console.println("There are " + count + " Signature fields which require signing.");
              
              
              1 person found this helpful
              • 4. Re: Digitally Sign All Signature Fields in the Active Document
                JoFrmOZ Level 1

                Thank you for your help, the script will now count only the signature fields which have not been signed.

                 

                I have added the second part of the script to then sign all of the blank signature fields.

                 

                The script is only signing one of the digital signature fields instead of all of the blank signature fields.

                 

                Can you please advise how I can modify the script to sign all of the blank signature fields?

                 

                var count = 0;

                 

                for (var i = 0; i < numFields; i++) {

                 

                    // Get the current field object

                    f = getField(getNthFieldName(i));

                 

                    // If it's a signature field and not already signed, increment counter

                    if (f.type === "signature" && !f.value) {

                        count++;

                    }

                }

                var myEngine = security.getHandler( "Adobe.PPKLite" );

                myEngine.login( "123", c/Documents and Settings/name/Application Data/Adobe/Acrobat/10.0/Security/FirstNameLastName.pfx" );

                // Sign the field

                f.signatureSign( myEngine,{password: "123"});

                 

                 

                 

                 

                 

                 

                • 5. Re: Digitally Sign All Signature Fields in the Active Document
                  George_Johnson MVP & Adobe Community Professional

                  How about this:

                   

                  var myEngine = security.getHandler("Adobe.PPKLite");
                  myEngine.login("123", "/c/Documents and Settings/name/Application Data/Adobe/Acrobat/10.0/Security/FirstNameLastName.pfx");
                  
                  for (var i = 0; i < numFields; i++) {
                  
                      // Get the current field object
                      var f = getField(getNthFieldName(i));
                  
                      // If it's a signature field and not already signed, sign it
                      if (f.type === "signature" && !f.value) {
                  
                          // Sign the field
                          f.signatureSign(myEngine, {password: "123"});
                  
                      }
                  }
                  
                  • 6. Re: Digitally Sign All Signature Fields in the Active Document
                    JoFrmOZ Level 1

                    Thank you very much for your assistance George.

                     

                    The script works perfectly and signs all signature fields which are blank.

                     

                    Your a legend!