3 Replies Latest reply on Jul 6, 2011 9:21 AM by Thom Parker

    Adding Icons to Toolbar

    Joe The Engineer Level 1

      I've seen a couple of examples of icons being added to toolbars and I'm trying to figure out the best way to do it:

       

      1)  AddToolbarsButton.pdf in the Javascript samples portfolio:  It looks like the icon is represented as a string which then is converted to an image using this little piece of code.

       

       

      //strtest is the string representing the icon image and it's like 1000 characters long or something.

      var iconStreamObj = {

          read: function readMyIcon(nBytes){

              var t = "";

              console.println("request for " +nBytes);

              while (pos < nBytes){

                  t = t+strtest;

                  pos += strtest.length;

              }

              return t;

          },

          width:17,

          height:20

      }

      Anyway, I'm kind of new to javascript and I can't figure out how they converted the icon to a string to be named as a variable in the script.  I've tried to do it, but haven't had much luck with it at all.  Also, In the samples javascript, I can't figure out where the variable nBytes comes from...

       

      2)  This.importIcon method in the javascript api reference doesn't make sense to me.  If i want to import an icon into a document, do i have to do it via javascript?  I guess I can assign it to an unseen button, but that seems kind of rinky-dink.  Is it impossible for me to embed it into the document manually through acrobat and then assign it via javascript?  If so, how?  I've also noticed the term "named icon", but I cannot figure out what that denotes.  I have several icons I'd like to use in my script as standalone toolbar buttons (i.e. not a button on a page). 
      Assuming these icons are in the same folder as the current document, is there a script I can use to import these icons into the document for use in toolbar buttons?  Do they have to be "PDF's" or "ico's"?  I've seen some online javascript that gave me the impression that file extensions were not used.  I would think that I could use a simple script like:

       

      this.importIcon("myIcon.ico");

       

      and that that script would embed the icon into the pdf where I could reference it at any point thereafter...

       

      Obviously, I'm kind of a newb to all this; so, if anyone could point me in the right direction with some heavily commented code or fool-proof descriptions, I'd be very appreciative.

       

      Thank You,

       

      jpc

        • 1. Re: Adding Icons to Toolbar
          gkaiseril MVP & Adobe Community Professional

          Reader can not import button icons. Reader can only use an icon stream.

           

          Acrobat can import a PDF for an Icon, but you would need to know where the pdf file is.

           

          Much easier and faster to create an Icon stream from a text object within the PDF or script file.

          • 2. Re: Adding Icons to Toolbar
            Joe The Engineer Level 1

            Ok, the sample script I have shows me how to create the icon from the text object.  Now all I need to know how to do is to generate the text object from an image or icon that i'd like to use in order to put it into my javascript.  The sample script doesn't show how to do that and I haven't had any luck finding it online so far either.  Anyone know how to generate a string from an icon???

            • 3. Re: Adding Icons to Toolbar
              Thom Parker Level 3

              The text image data is just that.  It's exactly the same data that is stored in memory for a 4 channel ARGB Bitmap, only it's encoded as Hexidecimal text rather than binary data. The reason for this encoding is that JavaScript does not handle binary data.  And these images are not just for toolbar buttons, they are used for popup custom dialogs as well

               

              There is a tool for creating Acrobat toolbar buttons called AcroButtons, it includes a tool for converting any standard image file into a icon stream object.  Actually, what the tool does is create a code template for an Acrobat Folder Level automation tool, where the button is a front end for the tool.

               

              You can also get detailed info on writing your own code for creating button icons by joining the pdfscripting.com web site and reading this article: http://www.pdfscripting.com/public/department35.cfm

               

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