Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adding a button with an icon -- RangeError

Participant ,
Nov 07, 2016 Nov 07, 2016

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!

TOPICS
Acrobat SDK and JavaScript , Windows
5.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 08, 2016 Nov 08, 2016

Hi Gilad,

I can't add a document button as I'd like to use this button in a PDF portfolio. I don't want to manually recreate the button when a document within a portfolio is updated.

I have no problem with dropping this icon but the problem is that the undocked toolbar w/o button icons looks terrible if more than one button is added to it. There is no separator between the buttons and there is (seemingly) no way to control the button text font/color.

Best regards,

Roman

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2016 Nov 08, 2016

It is working for me.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 08, 2016 Nov 08, 2016

That's interesting. Do you keep the icon in the same directory where the PDF is located?

Thanks,

Roman

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2016 Nov 08, 2016

No, I use a test directory.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 08, 2016 Nov 08, 2016

I wonder how Acrobat can switch to an absolute path like this one.

Which version of Acrobat do you use and what's your OS?

I use Acrobat 11 on Win7. I created a .png file out of a Visio file and saved it as an 20*20 pixel image.

Best regards,

Roman

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2016 Nov 08, 2016

No problem using a path like this:

"/C/Test/Home_Button.png"

Did you test your code in the debugger?

It will work with Acrobat 11 and Win 7.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 08, 2016 Nov 08, 2016

I tried it in the debugger as well. I get:

SyntaxError: syntax error

1:Console:Exec

undefined

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2016 Nov 08, 2016

Which code delivers this error?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 08, 2016 Nov 08, 2016

The one you posted above:

myButtonItem = app.trustedFunction( function()

{

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

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

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

});

Regards,

Roman

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2016 Nov 08, 2016

In the debugger you must select the whole code and execute it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 08, 2016 Nov 08, 2016

If I select the code and hit Enter, the function code is displayed again and nothing happens.

Regards,

Roman

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2016 Nov 08, 2016

hit ctrl-enter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 08, 2016 Nov 08, 2016

I get:

GeneralError: Operation failed.

App.addToolButton:20:Console undefined:Exec

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2016 Nov 08, 2016

The code has 7 lines. You get a error at line 20. What code did you execute?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 08, 2016 Nov 08, 2016

Sorry, I had another error text copied to the buffer (was testing another script) and I pasted it by mistake.

The error I get when running the script above (selected + Ctrl Enter) is:

SyntaxError: syntax error

1:Console:Exec

undefined

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2016 Nov 08, 2016

There is a error in your code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 08, 2016 Nov 08, 2016

Or there is something buggy in my Acrobat installation. You said the code works for you.

Is there a way to add a separator between such buttons?

Thanks,

Roman

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2016 Nov 08, 2016

Copy the above code, paste it in the console, select the whole code, and hit ctrl-enter.

This will define function nothing more.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 08, 2016 Nov 08, 2016

I understand that although it doesn't work for me.

But in case I don't want to use an icon and I create an undockable toolbar with 2 buttons using a doc-level script -- is there a way to add a separator between the buttons? In SDK, it is possible, but I don't see a way to do it in JS.

Thanks,
Roman

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2016 Nov 08, 2016
LATEST

I don't know.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2016 Nov 08, 2016

Did you test it in the JavaScript debugger?

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