5 Replies Latest reply on Dec 4, 2009 2:53 AM by Tschaedi

    addToolButton properties privilege issues

    Tschaedi Level 1

      Hello there,

       

      I'm trying to add a Toolbar Button with a JavaScript at folder-level and I have some privilege issues.

       

      I'd like the button to have an icon. But to open a doc to import the image I need a privileged context. Also the button needs to be like a on/off button, that stays marked when pressed once and becomes unmarked when pressed again. So this is what I tried...but which is unfortunately not working. Eventhough I set global.isBankStatement to false at the beginning the button is marked. I also tried to put cMarked: false and "false" but still the button is marked. Only when I omit the cMarked property it isn't marked.

       

      Any hint is appreciated ;-)

       

      (I'm working with Windows Vista and Acrobat 9 Pro)

       

      global.isBankStatement = false;

       

      var icon = app.trustedFunction(function(){
      app.beginPriv();
        var myDoc = app.newDoc();
        myDoc.importIcon("myIcon", "/C/acrobat_images/bank_20x20.gif", 0);
      var oIcon = util.iconStreamFromIcon(myDoc.getIcon("myIcon"));
        myDoc.closeDoc(true);
      return oIcon;
      });

       

      var marked = app.trustedFunction(function(){
      app.beginPriv();
      var result = global.isBankStatement;
      app.endPriv();
      return result;
      });


      app.addToolButton({
      cName: "myToolButton",
      oIcon: "icon",
      cExec: "handleBankStatements()",
      cTooltext: "Bank Statement",
      cEnable: "event.rc =(app.doc != null)",
      nPos: 1,
      cMarked: "event.rc = marked"
      });

        • 1. Re: addToolButton properties privilege issues
          try67 MVP & Adobe Community Professional

          Not sure if that's the cause of the problem, but sinced marked is a function you should call it like so:

          marked()

          • 2. Re: addToolButton properties privilege issues
            Thom Parker Level 3

            As far as calling the "marked" function try67 is correct.  All function calls must include parentheses.  Changes in Global object security have made working with it difficult, however using a trusted function is a bit of over kill.  There is another global space that will work for your button.  Try this code on your marked button.

             

            // Marked Input

            event.rc = app.media.bMyButtMarked;

             

            // Exec Code

            app.media.bMyButtMarked = !app.media.bMyButtMarked;

             

            As for getting the icon you are really going the long way around.  First, the "oIcon" argument takes an Object, not a string. So this is a bug in your code.

             

            Next, to make your icon portable you really need the Generic Icon Stream object definition in your folder level script.  To do this you could run your Icon import code once from the console window to get the generic Icon Stream object and then print out all the data.  You could even write a little routine that would format the data correctly for import into the folder level script. This way the folder level script does not depend on the gif file being on the system.

             

            To see what this looks like in real toolbar button code you can download and try out AcroButtons, which is a tool specifically for creating Acrobat toolbar buttons.  You could also goto www.pdfscripting.com and download any of the free automation tools.

             

            Thom Parker
            The source for PDF Scripting Info
            pdfscripting.com

             

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

             

            Then most important JavaScript Development tool in Acrobat
            The Console Window (Video tutorial)
            The Console Window(article)

            1 person found this helpful
            • 3. Re: addToolButton properties privilege issues
              Tschaedi Level 1

              Thank you very much for your hints. My marked function runs perfectly with the brackets ;-) I think I was confused because the anonymous function doesn't have brackets and because I'm new to Adobe JavaScript. But, it is true that your solution, Thom, is much more elegant.

               

              For my icon problem I understand that it isn't possible the way I'm trying it. But I don't quite understand how it could work.

              you could run your Icon import code once from the console window to get the generic Icon Stream object and then print out all the data

               

              What you are saying is that I could open a Document and import my Icon wihtin the Console right? But the folder-level scripts are run while opening Acrobat...so, at that time my icon Object is not yet known. So, where do I have to print the data to? A global variable? And how applicable is this method if I want to distribute this button to several users? Then you suggested:

              You could even write a little routine that would format the data correctly for import into the folder level script

               

              How should the data be formated with that little routine? Is this little routine another js file? Or does it have to be done within the console?

               

              I looked at the code that is generated whit AcroButtons but I couldn't get any hints from there.

               

              Thanks for your help.

              • 4. Re: addToolButton properties privilege issues
                Thom Parker Level 3

                What I'm saying is that the most efficient, robust, and portable way to deal with icons is to hard code the

                icon data into the script.  This is what AcroButtons does.  You'll notice that at the top of any of the scripts created with AcroButtons there is a block of Hexadecimal text.  This is the image data.  It's exactly what gets read out of the iconStream object.  Below this block is the code that defines the generic icon stream object, using this data.  Building this object is somewhat of an advanced topic.  The easy way to create toolbar buttons is to purchase AcroButtons, which is one of my products  But there's nothing wrong with your original methodology.  It'll work, you just have to assign an object to the "oIcon" input, not a string.

                 

                Thom Parker
                The source for PDF Scripting Info
                pdfscripting.com

                 

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

                 

                Then most important JavaScript Development tool in Acrobat
                The Console Window (Video tutorial)
                The Console Window(article)

                1 person found this helpful
                • 5. Re: addToolButton properties privilege issues
                  Tschaedi Level 1

                  Thanks for the hint with the hardcoding. Everything works fine now.