Adding a button with an icon -- RangeError
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
It is working for me.
Copy link to clipboard
Copied
That's interesting. Do you keep the icon in the same directory where the PDF is located?
Thanks,
Roman
Copy link to clipboard
Copied
No, I use a test directory.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I tried it in the debugger as well. I get:
SyntaxError: syntax error
1:Console:Exec
undefined
Copy link to clipboard
Copied
Which code delivers this error?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
In the debugger you must select the whole code and execute it.
Copy link to clipboard
Copied
If I select the code and hit Enter, the function code is displayed again and nothing happens.
Regards,
Roman
Copy link to clipboard
Copied
hit ctrl-enter
Copy link to clipboard
Copied
I get:
GeneralError: Operation failed.
App.addToolButton:20:Console undefined:Exec
Copy link to clipboard
Copied
The code has 7 lines. You get a error at line 20. What code did you execute?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
There is a error in your code.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Copy the above code, paste it in the console, select the whole code, and hit ctrl-enter.
This will define function nothing more.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I don't know.
Copy link to clipboard
Copied
Did you test it in the JavaScript debugger?


-
- 1
- 2