Creating add-ons toolbar button with custom icon

Explorer ,
Dec 26, 2017

Copy link to clipboard

Copied

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.

Your hex string worked fine for me. I'm able to generate valid hex strings that display the icon correctly on Windows but not on Mac. I'm just going to assume this is a Mac bug and generate my hex strings on Windows and paste into Mac. Thanks for the help.

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

2.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Creating add-ons toolbar button with custom icon

Explorer ,
Dec 26, 2017

Copy link to clipboard

Copied

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.

Your hex string worked fine for me. I'm able to generate valid hex strings that display the icon correctly on Windows but not on Mac. I'm just going to assume this is a Mac bug and generate my hex strings on Windows and paste into Mac. Thanks for the help.

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

2.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 26, 2017 0
Most Valuable Participant ,
Dec 26, 2017

Copy link to clipboard

Copied

Are you adding your code to the built-in config.js file? If so, that's a bad idea. You should create your own js file.

Beside that I'm not seeing any major issues. I tried your code on my machine and it worked fine...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 1
Most Valuable Participant ,
Dec 26, 2017

Copy link to clipboard

Copied

PS. Short of converting your image to a Hex string, which is super-complicated and annoying, your solution is the easiest one I've came across so far.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 1
Explorer ,
Dec 26, 2017

Copy link to clipboard

Copied

I'm on Mac and it's my own config.js file in /Applications/Adobe Acrobat DC/Adobe Acrobat.app/Contents/Resources/JavaScripts. There was not a config.js in there before I created mine. So with my code you were able to see a custom icon that you tested with? Also, do you know if there's a way to not have to create a dummy new document in order to import the icon?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 0
Most Valuable Participant ,
Dec 26, 2017

Copy link to clipboard

Copied

Do you have more than 1800 lines of code in that file?

And yes, it did work for me using a custom icon I saved in a local folder. And no, I don't think you can do it without creating a dummy document.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 1
Explorer ,
Dec 26, 2017

Copy link to clipboard

Copied

Yes, I have more than 1800 lines. Is that a problem?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 0
Most Valuable Participant ,
Dec 26, 2017

Copy link to clipboard

Copied

No, that's fine, I was just a bit surprised... So what's the full error message you're getting, and to which line in the code does it refer, exactly? Also, does it work if you remove the oIcon parameter?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 1
Explorer ,
Dec 26, 2017

Copy link to clipboard

Copied

The full error message I'm getting is just what I posted in my original question:

GeneralError: Operation failed.

App.addToolButton:1824:Folder-Level:App:config.js

app.addToolButton({

    cLabel: "Test1",

    cName: "testButton1",

    oIcon: myIcon,

    cExec: "app.alert('hello');",

    cTooltext: "Test1",

    cEnable: true,

    cMarked: true,

    nPos: 0

});

Line 9 above (nPos) is really line 1824 in my JavaScript file. Yes, the button shows up fine when I comment out the icon line (line 4 above).

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 0
Most Valuable Participant ,
Dec 26, 2017

Copy link to clipboard

Copied

In that case there's more than likely a problem with the file-path you're using. Are you sure you're using the correct syntax?

The best way to find out is to put a PDF in the same folder, then open it in Acrobat and run this code from the JS Console:

this.path

It will print out the correct file-path you need to use in the importIcon method.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 1
Explorer ,
Dec 26, 2017

Copy link to clipboard

Copied

I was using /Users/.. but when I opened a PDF in the same directory this.path started with /Macintosh HD/Users/..

So I tried that and I still get the same result.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 0
Explorer ,
Dec 26, 2017

Copy link to clipboard

Copied

It's also interesting that when I run app.getPath("user", "javascript") in the console I get:

GeneralError: Operation failed.

App.getPath:1:Console undefined:Exec

2

undefined

but I get a value for "app":

app.getPath("app", "javascript")

/Macintosh HD/Applications/Adobe Acrobat DC/Adobe Acrobat.app/Contents/Resources/JavaScripts/

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 0
Most Valuable Participant ,
Dec 26, 2017

Copy link to clipboard

Copied

The getPath result is expected. There's only an app version of this folder, not a user version.

I'm sorry, but I'm out of ideas. Could be a Mac-specific bug, as it's working fine in my Windows version, as I've said.

Maybe try the hex-string approach I mentioned before. That way you won't need to use an external image file, or a dummy document, either.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 1
Explorer ,
Dec 26, 2017

Copy link to clipboard

Copied

It doesn't seem like it's a file path issue because when I intentionally try a file path that doesn't exist I get an error back from the iconStreamFromIcon() function:

Util.iconStreamFromIcon:1801:Folder-Level:App:config.js

and when I put in a valid path I don't get an error back from iconStreamFromIcon().

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2017 0
Adobe Community Professional ,
Dec 27, 2017

Copy link to clipboard

Copied

You'll find a tutorial and a tool for creating toolbar Icons here:

Alerts, Popups, and Other Devices for Interacting with the User

You'll also find lots of folder level automation tools that use toolbar buttons with icons.  If you look at them you'll notice not a single one depends on an external file. Loading files at startup is iffy, and create dependencies that add difficulty to maintaining and transferring scripts.

Here are some free examples of tools with toolbar buttons:

Free Acrobat Automation Tools

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 27, 2017 1
Explorer ,
Dec 27, 2017

Copy link to clipboard

Copied

Thanks for the reply Thom, but unfortunately I don't have a subscription so can't see the examples.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 27, 2017 0
Engaged ,
Dec 27, 2017

Copy link to clipboard

Copied

You are not able to download the Free tools?  The first link was to an article on UI elements but the second one with sample tools using custom toolbar buttons is Free ( does not require a membership)

Free Acrobat Automation Tools

Any error messages when you tried to download the Free tools?

Hope this helps,

Dimitri

pdfscripting.com

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 27, 2017 1
Explorer ,
Dec 27, 2017

Copy link to clipboard

Copied

I must have only looked at the first link. I see the free tools now. Thanks guys! I'll check them out.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 27, 2017 0
Explorer ,
Dec 27, 2017

Copy link to clipboard

Copied

I was able to download them and checked out one of the examples of building a button with an icon using a hex string. So I tried that route and it looks some sort of icon or part of it but it doesn't really look like my image. Perhaps there's an issue with my hex string or with my image but the image is 20x20 px. I've tried a .jpg and a .png but get the same result. Are there any other image specs I need to satisfy for an icon image? What is the preferred way to get the hex string? I'm getting the hex string from the image via Java.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 27, 2017 0
Adobe Community Professional ,
Dec 27, 2017

Copy link to clipboard

Copied

It's critical that the image dimensions match the specified size in the icon object. And that the image data is ARGB. 4 bytes/8 hex digits per pixel. Otherwise, all the pixels get shifted.

This is the same data returned from the util.iconStreamFromIcon() function.

Since there are a few different bits that have to come together correctly, I created a set of examples/tools that do it for you, and show how it's done. But it's true the good stuff is paid content.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 27, 2017 1
Adobe Community Professional ,
Dec 27, 2017

Copy link to clipboard

Copied

Here is the spec for the icon stream object,which is what you pass into the app.addToolButton() function. This is the same object returned from the util.iconStreamFromIcon() function.

Acrobat DC SDK Documentation

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 27, 2017 0
Explorer ,
Dec 28, 2017

Copy link to clipboard

Copied

I'd like to inspect one of the images from the free examples you pointed me to since it displays correctly and my icon does not. Do you know if the original images are available anywhere or are the hex strings in the JS files the only option?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 28, 2017 0
Adobe Community Professional ,
Dec 28, 2017

Copy link to clipboard

Copied

Those were custom icons created by me. The images in other formats are not available.  But I don't see why that would be helpful. All you need to do is convert the pixel data into the specified format   

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 28, 2017 1
Adobe Community Professional ,
Dec 29, 2017

Copy link to clipboard

Copied

Here is a free PDF file that convert GIF, PNG, JPG… images to a usable format to embed into JavaScripts : Fichiers partagés - Acrobat.com

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 1
Explorer ,
Dec 29, 2017

Copy link to clipboard

Copied

I tried it out on a couple different .png files and a .jpg file and the icon still doesn't display correctly. I'm assuming there's something wrong with the image format I'm starting with but I'm not much of an image expert. Any way you can send me an image you've used with your tool that displays correctly so I can compare the specs to my images?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 0
Adobe Community Professional ,
Dec 29, 2017

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 1
Adobe Community Professional ,
Dec 29, 2017

Copy link to clipboard

Copied

It is extremely unlikely that there is something wrong with the image format you are starting with. But you probably do have an issue with the way the Hex data is being produced. How exactly are you creating the hex data? Please be specific

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 0
Explorer ,
Dec 29, 2017

Copy link to clipboard

Copied

I've tried generating the hex string in Acrobat using JS:

// create a document

var myDoc = app.newDoc();

// import icon from file

myDoc.importIcon("myIcon", "/some/path/myicon.png", 0);

// convert the icon to a stream

myIcon = util.iconStreamFromIcon(myDoc.getIcon("myIcon"));

// get hex string

var hex = myIcon.read();

// print hex string

console.println(hex);

then plugging that hex into:

var oIcon = {

     count: 0,

     width: 20,

     height: 20,

     read: function(nBytes) {

          return hex.slice(this.count, this.count += nBytes);

     }

};

then passing oIcon to the addToolButton() function. The result was that the image did not display correctly at all. Just a bunch of random black pixels.

I then tried the tool suggested above on the same icon image:

https://forums.adobe.com/external-link.jspa?url=https%3A%2F%2Ffiles.acrobat.com%2Fa%2Fpreview%2F1e38...

That gave a similar result. I then tried generating the hex string using the PDF tool above on the image provided further up in this thread:

https://forums.adobe.com/servlet/JiveServlet/showImage/2-10069142-1382811/Compteur-de-mots.png

That gave a similar result. Here is the hex string the tool generated for the image above:

0000000000000000ff8b1100ff8b1100ff970e1dff970e1dff860000ff860000ffc3091affc3091affa00000ffa00000ffa40802ffa40802ff9a0000ff9a0000ff940003ff940003ffa30712ffa30712ff9f0307ff9f0307ffa20407ffa20407ffa30005ffa30005ff990000ff990000ff9b0a06ff9b0a06ff920100ff920100ffb00e1effb00e1eff8e0000ff8e0000ffa31201ffa3120100000000000000000000000000000000ff8b1100ff8b1100ff970e1dff970e1dff860000ff860000ffc3091affc3091affa00000ffa00000ffa40802ffa40802ff9a0000ff9a0000ff940003ff940003ffa30712ffa30712ff9f0307ff9f0307ffa20407ffa20407ffa30005ffa30005ff990000ff990000ff9b0a06ff9b0a06ff920100ff920100ffb00e1effb00e1eff8e0000ff8e0000ffa31201ffa312010000000000000000ff951b00ff951b00ff7b0100ff7b0100ff950b1aff950b1affae1529ffae1529ffa50000ffa50000ffbe050dffbe050dff980000ff980000ffa50b04ffa50b04ff990008ff990008ff9f040eff9f040eff9f0408ff9f0408ff920000ff920000ffa10003ffa10003ffa9060affa9060aff900000ff900000ff960501ff960501ff980007ff980007ffbc1b2bffbc1b2bff7e0000ff7e0000ff9e240aff9e240aff951b00ff951b00ff7b0100ff7b0100ff950b1aff950b1affae1529ffae1529ffa50000ffa50000ffbe050dffbe050dff980000ff980000ffa50b04ffa50b04ff990008ff990008ff9f040eff9f040eff9f0408ff9f0408ff920000ff920000ffa10003ffa10003ffa9060affa9060aff900000ff900000ff960501ff960501ff980007ff980007ffbc1b2bffbc1b2bff7e0000ff7e0000ff9e240aff9e240aff840001ff840001ffb1272effb1272e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff90180cff90180cff930000ff930000ff840001ff840001ffb1272effb1272e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff90180cff90180cff930000ff930000ff970d13ff970d13ff840001ff8400010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff830a00ff830a00ff970100ff970100ff970d13ff970d13ff840001ff8400010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff830a00ff830a00ff970100ff970100ffaf0009ffaf0009ffa80002ffa800020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff9f070eff9f070effaa0009ffaa0009ffaf0009ffaf0009ffa80002ffa800020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff9f070eff9f070effaa0009ffaa0009ffab0004ffab0004ffb6030fffb6030f000000000000000000000000000000000000000000000000ff4c2b21ff4c2b21ff6e1417ff6e1417ff650b0eff650b0eff6e1324ff6e1324ff600919ff600919ff6d2227ff6d2227ff5c1115ff5c1115ff6a1b23ff6a1b23ff702029ff702029ff461d19ff461d19000000000000000000000000000000000000000000000000ff8e0000ff8e0000ffa00000ffa00000ffab0004ffab0004ffb6030fffb6030f000000000000000000000000000000000000000000000000ff4c2b21ff4c2b21ff6e1417ff6e1417ff650b0eff650b0eff6e1324ff6e1324ff600919ff600919ff6d2227ff6d2227ff5c1115ff5c1115ff6a1b23ff6a1b23ff702029ff702029ff461d19ff461d19000000000000000000000000000000000000000000000000ff8e0000ff8e0000ffa00000ffa00000ffaa090cffaa090cffa00002ffa00002000000000000000000000000000000000000000000000000ff4f1914ff4f1914ff7b1d1cff7b1d1cff781a19ff781a19ff6e1e25ff6e1e25ff58090fff58090fff6b1617ff6b1617ff72181bff72181bff75141eff75141eff6f0e1aff6f0e1aff511d1cff511d1c000000000000000000000000000000000000000000000000ffa30002ffa30002ffae0a09ffae0a09ffaa090cffaa090cffa00002ffa00002000000000000000000000000000000000000000000000000ff4f1914ff4f1914ff7b1d1cff7b1d1cff781a19ff781a19ff6e1e25ff6e1e25ff58090fff58090fff6b1617ff6b1617ff72181bff72181bff75141eff75141eff6f0e1aff6f0e1aff511d1cff511d1c000000000000000000000000000000000000000000000000ffa30002ffa30002ffae0a09ffae0a09ffa00002ffa00002ffa00002ffa000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffa80307ffa80307ff970000ff970000ffa00002ffa00002ffa00002ffa000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffa80307ffa80307ff970000ff970000ffa10305ffa10305ff9c0000ff9c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffa30300ffa30300ffa40100ffa40100ffa10305ffa10305ff9c0000ff9c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffa30300ffa30300ffa40100ffa40100ff9d0001ff9d0001ffa40609ffa40609000000000000000000000000000000000000000000000000ff58231fff58231fff5d2115ff5d2115ff5c1f13ff5c1f13ff47150eff47150eff63322bff63322bff601b13ff601b13ff5f1510ff5f1510ff65181aff65181aff65161eff65161eff4a181bff4a181b000000000000000000000000000000000000000000000000ffa30300ffa30300ffa40100ffa40100ff9d0001ff9d0001ffa40609ffa40609000000000000000000000000000000000000000000000000ff58231fff58231fff5d2115ff5d2115ff5c1f13ff5c1f13ff47150eff47150eff63322bff63322bff601b13ff601b13ff5f1510ff5f1510ff65181aff65181aff65161eff65161eff4a181bff4a181b000000000000000000000000000000000000000000000000ffa30300ffa30300ffa40100ffa40100ff9e0000ff9e0000ffa60700ffa60700000000000000000000000000000000000000000000000000ff542617ff542617ff61210bff61210bff691a09ff691a09ff6d1911ff6d1911ff771c16ff771c16ff6d1004ff6d1004ff73160aff73160aff5c130aff5c130aff632720ff632720ff582821ff582821000000000000000000000000000000000000000000000000ffa80005ffa80005ffa60004ffa60004ff9e0000ff9e0000ffa60700ffa60700000000000000000000000000000000000000000000000000ff542617ff542617ff61210bff61210bff691a09ff691a09ff6d1911ff6d1911ff771c16ff771c16ff6d1004ff6d1004ff73160aff73160aff5c130aff5c130aff632720ff632720ff582821ff582821000000000000000000000000000000000000000000000000ffa80005ffa80005ffa60004ffa60004ffa20400ffa20400ff9d0000ff9d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffa80005ffa80005ffa60004ffa60004ffa20400ffa20400ff9d0000ff9d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffa80005ffa80005ffa60004ffa60004

I also tried generating the hex string from the image file path in Java.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 0
Explorer ,
Dec 29, 2017

Copy link to clipboard

Copied

Here is a screen shot of Acrobat that shows the icon hex PDF generator tool and how after I select the file it loads it in fine and then on the Quick Tools toolbar you can see the red icon does not display correctly.

Screenshot at Dec 29 11-52-41.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 0
Adobe Community Professional ,
Dec 29, 2017

Copy link to clipboard

Copied

You're first bit of code is correct.  This is the same code that JR is using in his tool. However, you can't just assume the dimensions are 20x20. You actually have to check.  The image is "off" because the dimensions are off.


this.importIcon("myIcon"); 
myIcon = util.iconStreamFromIcon(this.getIcon("myIcon"));

var width = myIcon.width;

var height = myIcon.height;

You can do all this from the console widow using any open document. Unless you are creating an automation script, there is no need to make the new document. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 1
Explorer ,
Dec 29, 2017

Copy link to clipboard

Copied

Hmm, myIcon.width and myIcon.height return 40 but the image is really 20 x 20 pixels. When I try specifying a width and height of 40 in oIcon I get:

GeneralError: Operation failed.

App.addToolButton:1898:Folder-Level:App:config.js

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 0
Adobe Community Professional ,
Dec 29, 2017

Copy link to clipboard

Copied

toolbar icons are 20x20 or less. That's why you see the error. If the conversion is saying the image is 40x40 pixels then that's what it is. You may be seeing the 20x20 in a different parameter this isn't real pixels, such as points.  Edit the image in a tool that will allow you to resize it in true pixels.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 0
Explorer ,
Dec 29, 2017

Copy link to clipboard

Copied

It's definitely already 20 x 20 pixels which is why I'm confused.

Screenshot at Dec 29 13-24-16.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 0
Most Valuable Participant ,
Dec 29, 2017

Copy link to clipboard

Copied

I warned you, didn't I?

Actually, I don't think the issue is with the image size. It's with the format.

I had encountered similar issues when I messed around with these icons and finally I had to write a Java application that converts PNG images to an ARGB hex-string. But they come out rotated and flipped, so I have to rotate and flip them the other way in advance for them to come out correctly. It's a total nightmare...

Here's the hex-string I generated for your image:

"FFFFFFFFFFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFFFFFFFFFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFFFFFFFFFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFA30000FFFFFFFF"

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 1
Adobe Community Professional ,
Dec 29, 2017

Copy link to clipboard

Copied

I've never had an issue with Acrobat converting the image size incorrectly. I'd like to see if I have this same issue. Can you send me your png?  Send it too support@pdfscripting.com

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 1
Adobe Community Professional ,
Dec 30, 2017

Copy link to clipboard

Copied

you can see the red icon does not display correctly.

You must create and design icons at their final size: 20 x 20 pixels.

Otherwise, pixels are downsampled to fit this size, causing blurring and aliasing.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 30, 2017 0
Adobe Community Professional ,
Dec 30, 2017

Copy link to clipboard

Copied

It's definitely already 20 x 20 pixels which is why I'm confused.

About Apple Preview, aka "PDF Killer":

- Preview.app - Killer of PDF Files - KHKonsulting LLC

- https://www.abracadabrapdf.net/?p=558

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 30, 2017 0
Explorer ,
Jan 02, 2018

Copy link to clipboard

Copied

I tried emailing the icon to the email address you supplied but I'm getting the following error:

[personal information removed per policy - https://forums.adobe.com/docs/DOC-3731]

[This is an open forum, not Adobe support, please do not post personal information]

[If you are posting using email, please turn your 'sig file' function OFF for posting]

[WARNING - Adobe does not use Skype, so BEWARE of someone contacting you via Skype and claiming to be from Adobe]

No such user here (in reply to RCPT TO

   command)

Is this the correct address?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2018 0
Explorer ,
Jan 02, 2018

Copy link to clipboard

Copied

Thanks for the links but the first one doesn't apply since I'm dealing with a PNG, not a PDF in Preview.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2018 0
Adobe Community Professional ,
Jan 02, 2018

Copy link to clipboard

Copied

cschmelter  Just message me on this site. Put the cursor over my name and click on the Message button.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2018 1
Explorer ,
Jan 02, 2018

Copy link to clipboard

Copied

I just tried the hex string you generated and it displays correctly. How did you generate that hex string?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2018 0
Most Valuable Participant ,
Jan 02, 2018

Copy link to clipboard

Copied

Using a specialized tool in Java I created which converts normal PNGs to ARGB and outputs the result as a hex string.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2018 0
Adobe Community Professional ,
Jan 02, 2018

Copy link to clipboard

Copied

I just converted you PNG file with my own toolbar builder tool, which you can download from my site. This tool is a PDF document and the conversion is done with Acrobat JavaScript. It had no problems, but I'm on Windows, and you saying this icon on a Mac converts to 40x40 using Acrobat JavaScript? If true, then it is a bug.

Here's my result:

var strIconData = "00000000ff8a1400ff96101bff850300ffc20e17ff9f0500ffa30d00ff990400ff930401ffa20b10ff9e0704ffa10904ffa20502ff980400ff9a0e04ff910500ffaf111cff8d0300ffa2160000000000ff941e00ff7a0400ff940d18ffad1727ffa40500ffbd0b09ff970400ffa40f02ff980406ff9e080bff9e0806ff910400ffa00500ffa80b06ff8f0400ff950900ff970404ffbb1d29ff7d0200ff9d260aff830300ffb0282d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff8f1a0bff920400ff961011ff83030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff820d00ff960500ffae0506ffa7050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff9e0b0bffa90506ffaa0501ffb5090b000000000000000000000000ff4c2c21ff6e1516ff650d0dff6e1323ff600a18ff6d2226ff5c1214ff6a1b22ff702028ff461e19000000000000000000000000ff8d0300ff9f0500ffa90d09ff9f0500000000000000000000000000ff4f1914ff7a1e1bff771b18ff6e1e24ff580a0eff6b1717ff72191aff75151dff6f0f19ff511e1c000000000000000000000000ffa20500ffad0f06ff9f0500ff9f050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffa70804ff960400ffa00702ff9b040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffa20800ffa30600ff9c0400ffa30a06000000000000000000000000ff58241fff5c2215ff5b2013ff47160eff63322bff601c13ff5f1610ff651919ff65171dff4a181b000000000000000000000000ffa20800ffa30600ff9d0500ffa50c00000000000000000000000000ff542717ff60220cff681b09ff6c1a10ff761d16ff6c1203ff72170aff5c140aff632820ff582921000000000000000000000000ffa70502ffa50501ffa10900ff9c040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffa70502ffa50501ffaf0603ffaa060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff9e0704ffa10600ffab0600ffb30607000000000000000000000000ff4f2822ff5d2215ff631d13ff641916ff6c201dff63170eff5f120aff61312b0000000000000000000000000000000000000000ff9e0704ffa10600ffa10500ffa80806000000000000000000000000ff631c22ff6e1914ff6d1712ff752522ff661613ff660f08ff6a150dff6126230000000000000000000000000000000000000000ff9d0a01ffa50600ffa50504ffa0050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff9d0a01ffa50600ffa6101fff90030900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff8a0211ff9e050fff8c0305ffb71f3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff991120ff9b030dff931608ff740200ff991606ff8d0300ffaf0a02ffa40500ffa40505ffa90d0cff9f0706ff9f0706ffa80500ffa80500ffa40700ffa10800ff9e0704ff9e0704ff9a0400ffac1313ff7a0200ffac182000000000ffa32519ff920f00ff9c0d00ffaf0a02ff9f0500ffa80608ff950400ff9e0605ff9e0605ffa70500ffa70500ffa30500ffa00600ff9e0703ff9e0604ffa10a06ff9d0504ffb0181d00000000";

var oIconStream = {count:0, width:20, height:20,

     read:function(nBytes){return strIconData.slice(this.count,this.count+=2*nBytes)}};

// Action Script

var cButtJS = "app.alert('Hello Image Button',2)";

// Create Toolbar Button

app.addToolButton({cName:"TEst1", oIcon:oIconStream, cExec:cButtJS});

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2018 1
Adobe Community Professional ,
Jan 02, 2018

Copy link to clipboard

Copied

To easily get the hex string for any image, you can use my free Manage Icons 2.0 tool.

http://practicalpdf.com/actions-and-commands/

Use any PDF file to import the image as an icon using pPDF:Import Icon, then use pPDF Manage Icons to see list the icons in the document, then either "Get Hex" to get just the hex string or "Get Code" to get a JavaScript snippet that you can use in the rest of your code.

See that page for sample files and installation instructions.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2018 1
Explorer ,
Jan 02, 2018

Copy link to clipboard

Copied

Your hex string worked fine for me. I'm able to generate valid hex strings that display the icon correctly on Windows but not on Mac. I'm just going to assume this is a Mac bug and generate my hex strings on Windows and paste into Mac. Thanks for the help.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2018 0
Explorer ,
Jan 02, 2018

Copy link to clipboard

Copied

I tried your tool but the Import Icon command only allowed me to select .pdf files (not my .png).

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2018 0
Explorer ,
Jan 02, 2018

Copy link to clipboard

Copied

Your hex string worked fine for me. I'm able to generate valid hex strings that display the icon correctly on Windows but not on Mac. I'm just going to assume this is a Mac bug and generate my hex strings on Windows and paste into Mac.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2018 0
Adobe Community Professional ,
Dec 30, 2017

Copy link to clipboard

Copied

Here is the source JS file: https://adobe.ly/2q1y84S

of this free tool: https://www.abracadabrapdf.net/?p=964

which use one of above icons.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 30, 2017 0