Skip to main content
rombanks
Inspiring
November 7, 2016
Question

Adding a button with an icon -- RangeError

  • November 7, 2016
  • 45 replies
  • 6009 views

Hello folks,

I am working on a script that adds a custom button. Via a privileged function triggered thru a menu item, I can add a document-level script that creates this button.

However, when I try adding an icon to the button, the debugger throws an error:

RangeError: Invalid argument value.

Doc.importIcon:1:Document-Level:Add_Button

Here is my document-level script:

this.importIcon("HomeIcon", "C:\\Test\\Home_Button.png", 0);

var oIcon_Home = util.iconStreamFromIcon(this.getIcon("HomeIcon"));

app.addToolButton({cName: "Home", cExec: "app.alert('Test Message')", cEnable: "event.rc = (event.target != null);", cTooltext: "Home Screen"});

I suspect, Acrobat fails to access the C:\Test folder to create a PDF out of the icon file for some reason. Please, advise!

Thank you in advance!

This topic has been closed for replies.

45 replies

try67
Community Expert
Community Expert
November 7, 2016

Your file-path syntax is incorrect. In Acrobat the correct path for this file would be:

"/C/Test/Home_Button.png"

rombanks
rombanksAuthor
Inspiring
November 7, 2016

Hi Gilad,

The first thing I tried was:

"/C/Test/Home_Button.png"

It didn't work. So I've changed it to the Win notation.

BTW, the second/third lines should be (omitted the oIcon):

app.addToolButton({cName: "Home", oIcon: oIcon_Home, cExec: "app.alert('Test Message')", cEnable: "event.rc = (event.target != null);", cTooltext: "Home Screen"});

Best regards,

Roman

try67
Community Expert
Community Expert
November 7, 2016

From the documentation of importIcon:

Note: If cDIPath is specified, this method can only be executed during a batch or console event. See

Privileged versus non-privileged context for details. The event object contains a discussion of

Acrobat JavaScript events.

This means that if you want to use this method from the doc-level and to specify the file-path of the image, it needs to be backed by a trusted folder-level script.