20 Replies Latest reply on Nov 1, 2016 1:58 AM by heresha93876846

    Add a Menu Item for a Sign Signature Field Script

    Jo_2005 Level 1

      Hello,

       

      I have multiple time sheets which need to have a script to sign digital signature fields.

       

      I have a "Sign Singature Field Script" which works perfectly when used in Batch Processing.

       

      I would like to add a menu item for this script rather than using batch processing, as the user only has access to Adobe Reader.

       

      I have created a js extension file but this is not creating the menu item.

       

      Can anyone please advise where this code needs revising:

       

      app.addMenuItem({ cName: "Time Sheet Approval", cParent: "Document", cExec: "var myEngine = security.getHandler( "Adobe.PPKLite" ); myEngine.login( "password", "/c/Documents and Settings/User Name/Application Data/Adobe/Acrobat/8.0/Security/User Name.pfx" );
      var f = this.getField("Supv Signature"); // Sign the field f.signatureSign( myEngine,{password: "password"});",cEnable: 1, nPos: 12});

       

      If this script cannot be used to add a menu item, any suggestions would be appreciated as to where else this script can be placed on the document without using batch processing?

       

       

      Thank you, any assitance will be greatly appreciated.

       

        • 1. Re: Add a Menu Item for a Sign Signature Field Script
          try67 MVP & Adobe Community Professional

          You can't place the entire script in the cExec parameter. This parameter should call a local function
          that contains your script, like so:

          app.addMenuItem({ cName: "Time Sheet Approval", cParent: "Document", cExec: "sign()", cEnable: 1, nPos: 12});

          function sign() {
          var myEngine = security.getHandler( "Adobe.PPKLite" ); myEngine.login( "password", "/c/Documents and Settings/User Name/Application Data/Adobe/Acrobat/8.0/Security/User Name.pfx" );
          var f = this.getField("Supv Signature"); // Sign the field
          f.signatureSign( myEngine,{password: "password"});

          }

          • 2. Re: Add a Menu Item for a Sign Signature Field Script
            Jo_2005 Level 1

            Thank you so much for your help.

             

            The Custom Menu Item "Time Sheet Approval" now appears under the main menu of "Document" and the script executes and digitally signs the document:

             

            function sign() {
            var myEngine = security.getHandler( "Adobe.PPKLite" );
            myEngine.login( "password", "/c/Documents and Settings/username/Application Data/Adobe/Acrobat/8.0/Security/UserName.pfx" );
            var f = this.getField("Supv Signature");
            f.signatureSign( myEngine,
            {password: "password"});
            }


            app.addMenuItem({ cName: "Time Sheet Approval", cParent: "Document", cExec: "sign()", cEnable: 1, nPos: 12});

             

            I greatly appreciate your assistance!

             

             

            • 3. Re: Add a Menu Item for a Sign Signature Field Script
              Jo_2005 Level 1

              Hello,

               

              I have another twist to add to the script.

               

              There is a text field below the digital signature field called "Todaydate2" which is required to show today's date when the document is signed.

               

              I have amended the cExec part of the add menu item, but now the custom "Time Sheet Approval" menu item does not appear.

               

              Can you please advise how the script can be amended to include the two functions?

               

              The script is as follows:

               

              function sign() {
              var myEngine = security.getHandler( "Adobe.PPKLite" );
              myEngine.login( "password", "/c/Documents and Settings/username/Application Data/Adobe/Acrobat/8.0/Security/UserName.pfx" );
              var f = this.getField("Supv Signature");
              f.signatureSign( myEngine,
              {password: "password"});
              var g = this.getField("Todaydate2");
              g.value = util.printd("d/mm/yyyy", new Date());");
              }


              app.addMenuItem({ cName: "Time Sheet Approval", cParent: "Document", cExec: "sign()", cEnable: 1, nPos: 12});

              • 4. Re: Add a Menu Item for a Sign Signature Field Script
                try67 MVP & Adobe Community Professional

                In this line:

                g.value = util.printd("d/mm/yyyy", new Date());");

                why did you insert the last three characters : ");

                They do not correspond with any other ones and should be removed.

                1 person found this helpful
                • 5. Re: Add a Menu Item for a Sign Signature Field Script
                  Jo_2005 Level 1

                  Thank you so much for your advice.

                   

                  I have removed the extra characters "); from the script and it now works perfectly.

                   

                  The reason the extra characters were there, was because the script was copied from an existing batch processing script to add a signature field with associated set actions which required the closing "); characters.

                   

                  I have also since added to my script so that the document is signed, the text field inserts today's date and then the time sheet is emailed to a recipient and the document is then closed.

                   

                  I would not have successfully been able to complete this without your very valuable help. 

                   

                  Thanks once again.

                   

                  The complete script is listed as follows for reference:

                   

                  function sign() {

                  var myEngine = security.getHandler( "Adobe.PPKLite" );
                  myEngine.login( "password", "/c/Documents and Settings/username/Application Data/Adobe/Acrobat/8.0/Security/UserName.pfx" );
                  var f = this.getField("Supv Signature");
                  f.signatureSign( myEngine,
                  {password: "password"});
                  var g = this.getField("Todaydate2");
                  g.value = util.printd("d/mm/yyyy", new Date());
                  this.mailDoc({bUI: false,cTo: "emailaddress",
                  cSubject: "Email Subject",
                  cMsg: "Email Message"'});
                  app.execMenuItem("SaveAs");

                  this.closeDoc(true);

                  }

                   

                  app.addMenuItem({ cName: "Time Sheet Approval", cParent: "Document", cExec: "sign()", cEnable: 1, nPos: 12});

                   

                  • 6. Re: Add a Menu Item for a Sign Signature Field Script
                    Jo_2005 Level 1

                    Hello Again,

                     

                    I have a final glinch with my script that needs some help to clarify.

                     

                    The script works perfectly in Adobe Professional 8.0.

                     

                    The person who will be using this script has Adobe Reader 8.0 and the custom menu item "Time Sheet Approval" is shown, but when clicked there is an error message as follows:

                     

                    "An internal error occurred".

                     

                    The document has been reader enabled for digital signing.

                     

                    Can you please advise what the error could be with the script to be used with Adobe Reader 8.0?

                     

                    function sign() {

                    var myEngine = security.getHandler( "Adobe.PPKLite" );
                    myEngine.login( "password", "/c/Documents and Settings/username/Application Data/Adobe/Acrobat/8.0/Security/UserName.pfx" );
                    var f = this.getField("Supv Signature");
                    f.signatureSign( myEngine,
                    {password: "password"});
                    var g = this.getField("Todaydate2");
                    g.value = util.printd("d/mm/yyyy", new Date());
                    this.mailDoc({bUI: false,cTo: "emailaddress",
                    cSubject: "Email Subject",
                    cMsg: "Email Message."});
                    app.execMenuItem("SaveAs");
                    this.closeDoc(true);

                    }

                     

                    app.addMenuItem({ cName: "Time Sheet Approval", cParent: "Document", cExec: "sign()", cEnable: 1, nPos: 12});

                    • 7. Re: Add a Menu Item for a Sign Signature Field Script
                      Jo_2005 Level 1

                      Hello,

                       

                      I have been able to fix the internal error in the custom menu item by passing the "trusted function".

                       

                      The script is as follows:

                       

                      function myOtherTrustedFunction()
                      {
                      app.beginPriv();
                      var myEngine = security.getHandler( "Adobe.PPKLite" );
                      myEngine.login( "password", "/c/Documents and Settings/username/Application Data/Adobe/Acrobat/8.0/Security/UserName.pfx" );
                      var f = this.getField("Supv Signature");
                      f.signatureSign( myEngine,
                      {password: "password"});
                      var g = this.getField("Todaydate2");
                      g.value = util.printd("d/mm/yyyy", new Date());
                      this.mailDoc({bUI: false,cTo: "email address",
                      cSubject: "Email Subject",
                      cMsg: "Email Message."});
                      app.execMenuItem("SaveAs");
                      this.closeDoc(true);
                      app.endPriv();
                      }

                      app.trustedFunction(myOtherTrustedFunction);


                      app.addMenuItem({ cName: "Time Sheet Approval", cParent: "Document", cExec: "myOtherTrustedFunction()", cEnable: 1, nPos: 12});

                       

                       

                      • 8. Re: Add a Menu Item for a Sign Signature Field Script
                        heresha93876846

                        Can I use this code for Acrobat DC and if so where does it go?

                        • 9. Re: Add a Menu Item for a Sign Signature Field Script
                          try67 MVP & Adobe Community Professional

                          You can try, but a lot has changed since this code was posted in terms of security.

                          You'll need to change the path to the pfx file, of course, as well as the cParent value from "Document" to something else, like "Edit". There might also be other things that need to be adjusted that I'm not seeing right now...

                           

                          The folder where you need to place the .js file depends on your OS. On Windows it will be:

                          C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts

                          1 person found this helpful
                          • 11. Re: Add a Menu Item for a Sign Signature Field Script
                            heresha93876846 Level 1

                            I read in acrobat dc developer guide that I need to find the user Javascript folder, do u know where that is?

                             

                            I cnat find it by running:

                            app.getPath({cCategory: "user", cFolder: "javascript"})

                            • 12. Re: Add a Menu Item for a Sign Signature Field Script
                              try67 MVP & Adobe Community Professional

                              Use the app folder, not the user one.

                               

                              On Oct 28, 2016 12:52 PM, "heresha93876846" <forums_noreply@adobe.com>

                              • 13. Re: Add a Menu Item for a Sign Signature Field Script
                                Bernd Alheit Adobe Community Professional & MVP

                                heresha93876846 wrote:

                                 

                                I read in acrobat dc developer guide that I need to find the user Javascript folder, do u know where that is?

                                 

                                I cnat find it by running:

                                app.getPath({cCategory: "user", cFolder: "javascript"})

                                What did you get when you run the code?

                                • 14. Re: Add a Menu Item for a Sign Signature Field Script
                                  heresha93876846 Level 1

                                  It just didnt do anything. However I know now howto add menu items in Acrobat DC.

                                  goto "C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts\"

                                  Create config,js and pu the code there. However I cant get the menu iutem to trigger the function:

                                   

                                  The code (it should just open a brose for fie page)

                                   

                                  app.addMenuItem({cName:"Heresh Toolkit", cParent:"Edit", cExec:"back()" });

                                  function back(){

                                  app.browseForDoc()

                                  }

                                   

                                  It just says the app has stopped working.

                                  • 15. Re: Add a Menu Item for a Sign Signature Field Script
                                    heresha93876846 Level 1

                                    It says "an internal error has occured".

                                    • 16. Re: Add a Menu Item for a Sign Signature Field Script
                                      Bernd Alheit Adobe Community Professional & MVP

                                      Repair your Acrobat installation.

                                      • 17. Re: Add a Menu Item for a Sign Signature Field Script
                                        try67 MVP & Adobe Community Professional

                                        There's already a file called config.js in that folder. Do NOT edit or

                                        delete it. It will prevent scripts from running correctly in your

                                        application.

                                        You need to create your own js file.

                                        • 18. Re: Add a Menu Item for a Sign Signature Field Script
                                          heresha93876846 Level 1

                                          Can I just create a file and name it whatever.js and it will be loaded at acrobat startup?

                                          • 19. Re: Add a Menu Item for a Sign Signature Field Script
                                            Bernd Alheit Adobe Community Professional & MVP

                                            Yes, it must have only the extension .js