Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - create toolbar button or menu item
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

create toolbar button or menu item

 Post Reply Post Reply
Author
squidfish View Drop Down
New Member
New Member


Joined: 15 Feb 2013
Points: 3
Post Options Post Options   Quote squidfish Quote  Post ReplyReply Direct Link To This Post Topic: create toolbar button or menu item
    Posted: 15 Feb 2013 at 9:25am
Hi,
I am an experienced programmer, but new to Acrobat. I have written a javascript which manipulates the bookmarks in a document, and that is working fine. However, at the moment the only way I can see to run it is to open my document, then CTRL+J to open the debugger, paste my code into the console and run it from there.
What I would like is to have a button on the toolbar, or an item in the menu somewhere which can run the script for any document I open.
I thought this would be the easy bit, but I can't find how to do it. Can someone help?
 
Many thanks in advance, and apologies as I'm sure this is a total noob question.
 
Squidfish
Back to Top
Sponsored Links


Back to Top
squidfish View Drop Down
New Member
New Member


Joined: 15 Feb 2013
Points: 3
Post Options Post Options   Quote squidfish Quote  Post ReplyReply Direct Link To This Post Posted: 15 Feb 2013 at 9:26am
Sorry, I meant to say I am using Acrobat Pro 9
Back to Top
aandi View Drop Down
Senior Member
Senior Member


Joined: 07 Jul 2011
Points: 18358
Post Options Post Options   Quote aandi Quote  Post ReplyReply Direct Link To This Post Posted: 15 Feb 2013 at 9:56am
In SDK, see JavaScript > Developing Acrobat Applications Using JavaScript > Modifying the User Interface
Acrobat 9 is the last release where you can add a button I think.
Back to Top
squidfish View Drop Down
New Member
New Member


Joined: 15 Feb 2013
Points: 3
Post Options Post Options   Quote squidfish Quote  Post ReplyReply Direct Link To This Post Posted: 15 Feb 2013 at 12:07pm
Hi,
Thanks for this - I have now managed to put a menu item onto the Tools menu which will pop up a message box when clicked. I did this by putting this script:
 
app.addMenuItem({cName:"Menu Test", cParent: "Tools",   
    cExec: "app.alert('Menu Item Test'); "});
 
into a text file and saving it into C:\Users\<username>\AppData\Roaming\Adobe\Acrobat\9.0\JavaScripts\mytool.js
 
This is OK, but when I try to substitute my code for "app.alert('Menu Item Test'); " in cExec, it says something about unbalanced quotes. My script does have double quotes, so I trued changing them all to single quotes but that doesn't work. I am thinking there must be a way to get the cExec to just call a function / procedure (sorry, don't know the right terminology in JavaScript). How would I do that? And where would I store the code for the called procedure?
 
So, I am wanting to put something like this:
 
app.addMenuItem({cName:"Menu Test", cParent: "Tools",
cExec: "call myBookmarkCode(); "});
 
and have some code somewhere called myBookmarkCode. How do I do this?  Sorry - like I say I have been programming for many years, but programming JS in acrobat is new to me.
 
Thanks,
 
Squidfish
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4108
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 15 Feb 2013 at 7:13pm

cExec is the JavaScript statement or statement to execute. If you have a function, then you only need to call the function.

app.addMenuItem( { cName: "myBookmark",
cUser: "My Bookmark Function",
cParent: "Tools",
cExec: "myBookmarkCode()",
cEnable: "event.rc = event.target != null;"
});
 
I assume you have a working function named "myBookmarkCode".
 
You also might want this menu item only active when a PDF is open.
 
Back to Top
aandi View Drop Down
Senior Member
Senior Member


Joined: 07 Jul 2011
Points: 18358
Post Options Post Options   Quote aandi Quote  Post ReplyReply Direct Link To This Post Posted: 16 Feb 2013 at 7:16pm
In JavaScript, like .C, C++, Java and some others, you have to escape quotes with backslash.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.063 seconds.