Creating add-ons toolbar button with custom icon
I have a folder level JavaScript that is running when Acrobat starts up. I'm able to add a button to the add-ons toolbar without a custom icon but once I try to specify an icon I get an error that doesn't tell me much.
GeneralError: Operation failed.
App.addToolButton:1824:Folder-Level:App:config.js
Here is my code:
var myIcon;
var importIcons = app.trustedFunction(function() {
app.beginPriv();
// Create a document
var myDoc = app.newDoc();
// import icon (20x20 pixels) from the file specified
myDoc.importIcon("myIcon", "/some/path/plus.jpg", 0);
// convert the icon to a stream.
myIcon = util.iconStreamFromIcon(myDoc.getIcon("myIcon"));
// close the doc now that we have grabbed the icon stream
myDoc.closeDoc(true);
app.endPriv();
});
importIcons();
// add buttons to add-ons toolbar
app.addToolButton({
cLabel: "Test1",
cName: "testButton1",
oIcon: myIcon,
cExec: "app.alert('hello');",
cTooltext: "Test1",
cEnable: true,
cMarked: true,
nPos: 0
});
My image is 20x20 px and a .jpg. I'm also wondering if there's a way to accomplish this without having to create a dummy empty document just in order to call importIcon() and getIcon(). Any help is appreciated.
