13 Replies Latest reply on Apr 13, 2009 11:29 PM by Abcde name

    Help with Acrobat js created menu button

    Abcde name Level 1

      I as using a short javascript which creates a menu button. The js script is in the correct Acrobat javascripts folder. I am using Acrobat Pro 8.1.2

       

      var oButObjAddSigningPage =
      {cName: "AddSignPage",
      cEnable: "event.rc = (app.doc != null)",
      cExec: "AddSigningPage()",
      cLabel: "Add Signing Page",
      cTooltext: "Add signing page to the current document"
      };

      try
      {
          app.addToolButton(oButObjAddSigningPage);
      }catch(e){console.println(e);}

       

      The function AddSigningPage()" is in the same script file.

       

      Problem: The button loads and displays correctly (greyed out) if Acrobat is launched. If a pfd file is then loaded the button comes alive and the function works OK .

      But the button does not display at all if Acrobat is launched by clicking on a pdf file.

       

      Help please.

        • 1. Re: Help with Acrobat js created menu button
          Bernd Alheit Adobe Community Professional & MVP

          No Problem with this JavaScript code.  I am using Acrobat Pro 8.1.4.

          • 2. Re: Help with Acrobat js created menu button
            Abcde name Level 1

            But the button does not display at all if Acrobat is launched by clicking on a pdf file.

             

            There must be something else I need to do when Acrobat is launched by a pdf file.

            • 3. Re: Help with Acrobat js created menu button
              Bernd Alheit Adobe Community Professional & MVP

              The button does display if Acrobat is launched by clicking on a pdf file.

              • 4. Re: Help with Acrobat js created menu button
                Abcde name Level 1

                It does sometimes load the button when launching a pdf file. It seems inconsistent. I would say approx 50% of the time it does not. I just tried it twice with the same file and once the button loaded. Second time it did not. This is the same experience for myself here and others users here. It is a problem.

                 

                Is there anything I can check when Acrobat launches without the button to find out why when the button does not load?

                Thanks for any advice.

                • 5. Re: Help with Acrobat js created menu button
                  Bernd Alheit Adobe Community Professional & MVP

                  You can look at the JavaScript Debugger. And you can update to version 8.1.4.

                  • 6. Re: Help with Acrobat js created menu button
                    Patrick Leckey Level 3

                    Once Acrobat is open hit CTRL+J to open the JS Console.  It will list any errors encountered during the parsing of folder-level Javascripts.

                     

                    Keep in mind that Acrobat parses folder-level Javascripts after initializing the viewer, so it can sometimes take 5 - 10 seconds after the viewer is open for any added buttons / menu items to show up.

                    • 7. Re: Help with Acrobat js created menu button
                      Abcde name Level 1

                      Thankyou for the responses.

                       

                      1. This is a large corporate controlled infrastructure with ~40,000 global desktops centrally IT managed. In its favour it is a stable environment. I have influence but I cannot control upgrade of anything. (We are still on Office 2003 !).

                       

                      2. I launched (the same document), the button did not appear. I gave it some time, did CNTL J to launch the console. (I have noticed it takes ~ a few secs to display the menu button on launching Acrobat). No errors displayed in the console. No menu button.

                      Console displays the usual:

                      Acrobat JavaScript Debugger Functions Version 7.0
                      Acrobat Database Connectivity Built-in Functions Version 8.0
                      Acrobat EScript Built-in Functions Version 8.0
                      Acrobat Annotations / Collaboration Built-in Functions Version 8.0
                      Acrobat Annotations / Collaboration Built-in Wizard Functions Version 8.0
                      Acrobat Multimedia Version 8.0
                      Acrobat SOAP 8.0

                       

                      V Strange problem I appreciate. Surely there is something to force the loading of the JS scripts in the javascript folder. Maybe a folder script I can use on open of any document?

                       

                      Again - your help much appreciated.

                      • 8. Re: Help with Acrobat js created menu button
                        Bernd Alheit Adobe Community Professional & MVP

                        What can you see in the Scripts window of the Debugger?

                        1 person found this helpful
                        • 9. Re: Help with Acrobat js created menu button
                          Patrick Leckey Level 3
                          Surely there is something to force the loading of the JS scripts in the javascript folder.

                          No, because the scripts are always loaded on every new Acrobat process.  In fact, there is no way to NOT load them.

                           

                          Make sure you have closed ALL your Acrobat windows (including anything open in the browser).  Bring up the Task Manager and kill the Acrobat.exe process just to be sure - Acrobat will only parse the contents of that folder on a new process launch, it will not do so when a new instance of an existing process is spawned.

                          1 person found this helpful
                          • 10. Re: Help with Acrobat js created menu button
                            Abcde name Level 1

                            Checked task manager - no acrobat.exe running.

                            Launched pdf file. No button appears in Acrobat.

                            Scripts window of debugger is blank.

                            Console has no errors.

                             

                            Repeated 10 times - same result every time.

                             

                            Launch Acrobat and the button appears.

                             

                            Close Acrobat. Launched pdf file. No button appears in Acrobat.

                            Open console

                            app.removeToolButton(oButObjAddSigningPage); <-fails
                            Exception in line 1 of function top_level, script Console:Exec

                            GeneralError: Operation failed.

                            The toolbutton specified could not be found

                             

                            i.e. the button appears not to have been loaded.

                             

                            Console

                            app.addToolButton(oButObjAddSigningPage); <- two buttons appear.
                            undefined

                            app.removeToolButton(oButObjAddSigningPage); <- one button disapears.

                            undefined

                            • 11. Re: Help with Acrobat js created menu button
                              Abcde name Level 1

                              I am beginning to see a clue.

                              The pdf file I have trying this on now seems to never allow the button to load.

                              Trying with different pdf files the button does always load.

                               

                              I think the clue is that the add and remove toolbar feature is context sensitive.

                              e.g. doing this with a document loaded always fails:

                              app.removeToolButton(oButObjAddSigningPage);

                              It is a shame it says it cannot find the button when it should say the context is wrong.

                               

                              This is because the button was loaded with Acrobat before the document was loaded. Removing the button can only be done when no document is present. Similarly if the button was created while a document is loaded then the button disappears when the document is closed, and reappears when the document is opened.

                               

                              Doesn't quite explain my problem but seems a clue. I will throw away my test document and move on to others.

                               

                              Thanks for the suggestions.

                              • 12. Re: Help with Acrobat js created menu button
                                Thom Parker Level 3

                                The proper input to the "app.removeToolButton" function is the name of the toolbar button, not the object that was used to create it.  Try this:

                                 

                                app.removeToolButton("AddSignPage");

                                 

                                The very first thing you need to check for is the "Add-ons" toolbar.  After loading your document, and when the toolbar button doesn't show.  Right click on an empty portion of the Acrobat Toolbar to display a list of all the individual toobars.  Is there an Add-ons Toolbar Listed?  Is it checked?

                                 

                                To determine if your Folder level script was loaded and run, Test the function created in that script.

                                Run this from the console window

                                 

                                     AddSigningPage

                                 

                                The code for the function will be returned if is was defined.

                                 

                                To determine if your toolbar button was loaded, run this code from the console window.

                                 

                                var lst = app.listToolbarButtons()
                                for(var i=0;i<lst.length;i++){
                                  if(lst[i].cName == "JSAppToolBar")
                                    console.println(lst[i]);
                                }

                                the "JSAppToolBar" is the internal name of the "Add-ons" toolbar.

                                 

                                However, from what you have described it does look as if you've hit on a bug.  Probably a timing issue.  What are the characteristics of this file?

                                 

                                Thom Parker
                                WindJack Solutions
                                The source for PDF Scripting Info
                                http://www.pdfScripting.com


                                The Acrobat JavaScript Reference,  Use it Early and Often
                                http://www.adobe.com/devnet/acrobat/javascript.html

                                • 13. Re: Help with Acrobat js created menu button
                                  Abcde name Level 1

                                  Thanks Thom. That check for the JSAppToolBar is useful.

                                   

                                  The problematic pdf file has been deleted so I cannot examine it futher.

                                   

                                  Thanks for everyone's help.