These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

custom toolbar button icons

drosales
Registered: Jun 3 2011
Posts: 25
Answered

Hello all!
 
Can someone point me to some JS examples for adding icons to custom toolbar buttons. i was able to add some toolbar buttons, but they have default icons that look like lego blocks. I downloaded a sample icon image to test it out. its from favicon and has an ".ico" extension. is that a usable file for button icons.

My Product Information:
Acrobat Pro 10.0.1, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
If you can access the icon image, it is an easy import. If you are going to include the icon data within JavaScirpt code, it is more complex. See Icons in Acrobat: and then use the icon stream read method in JavaScript to create an icon stream that can be converted icon stream for inclusion in a button. the AcroButtons product from Windjack Solutions has demos for the code to create buttons with images. There are also samples in the AcroDialog product. This is really advanced processing.

George Kaiser

drosales
Registered: Jun 3 2011
Posts: 25
thanks George, but the link is to WindJack and you have to purchase the product. i was looking for some actual code examples to follow.
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
Accepted Answer
If you read the JavaScript documentation, you can see how it works - in particular the app.addToolButton() method, the IconStream object and util.iconStreamFromIcon() to get the hex-code for your final script. Note that as of version X you cannot place a button on the toolbar automatically, no matter what code you write - it will ALWAYS appear on the Tools Pane, down at the bottom corner - from where the user has to manually drag it into the Quick Tools area.

From the SDK, here's a VERY barebones example:

// Create a document
var myDoc = app.newDoc();
// import icon (20x20 pixels) from the file specified
myDoc.importIcon("myIcon", "/C/myIcon.jpg", 0);
// convert the icon to a stream.
oIcon = util.iconStreamFromIcon(myDoc.getIcon("myIcon"));
// close the doc now that we have grabbed the icon stream
myDoc.closeDoc(true);
// add a toolbutton
app.addToolButton({
cName: "myToolButton",
oIcon: oIcon,
cExec: "app.alert('Someone pressed me!')",
cTooltext: "Push Me!",
cEnable: true,
nPos: 0
});
drosales
Registered: Jun 3 2011
Posts: 25
Thanks UVSAR, i'll give it a try.