Installation
Download and extract the zip file, and save the files into the JavaScripts folder. Then restart PDF-XChange. More detailed installation instructions here: viewtopic.php?p=196006#p196006
Usage
When installed it will add a new menu (or ribbon) named "JS": When you run the tool, it opens a dialog to enter script snippets:
On the left is a list of your saved snippets, with buttons to
- [ + ] add a new snippet,
[▲] [▼] move the selected snippet up or down the list, or
[ - ] delete it.
On the top right is:
- The name of the currently selected script (as displayed in menus);
- a button to run the current script and
- an area to enter the javascript:
- The tool runs each script inside its own function, with this = current pdf document. All the variables are contained in this scope: If a script needs to create variables in the global scope, try setting globalThis.yourGlobalVariable = "in global scope". The variable scriptID has the id number that this script has been assigned.
- Run Function at application startup will run the script when the program first starts. This is useful if you want to set up some functions or properties that your menu will later use. If you want to have a menu item, then this script must return a script/function; that function will be run by the menu item.
Add button/menu item allows one to just save a snippet without having a button or menu assigned to it. Scripts can be run from the button in the top right of the dialog.
Mark as Trusted Function Generally scripts are prevented from doing things that could damage documents. This option removes that restriction, so if the script is getting error "NotAllowedError: Security settings prevent access to this property or method." then the script probably needs this box checked.If you are concerned about this script running arbitrary trusted functions, one can completely disable that functionality by changing line 20 of snippetMenus.js:Ribbon UI and Classic UI are the language-independent names of the parent menu items for the button. The dropdown has some typical locations, but I've included Tracker Software's script "Show Classic/Ribbon UI menu structure" that will output the names for all menu items to the console.Code: Select all
const ALLOW_TRUSTEDFUNCTION = false; // set false to prevent running trusted functions
Position is the position within the submenu to locate the new menu item. Specifying -1 appends it to the end of the submenu. Specifying 0 adds it to the top of the submenu. The value of nPos can also be the language-independent name of a menu item.
Keyboard is keyboard shortcut for this menu item.
Icon [Select] opens another dialog to specify the icon for the menu:- cIconID string is a special unique ID for an existing vector icon in Editor. I've put a dropdown with the full list of icon IDs. It's the same id as shows up under Customize > Command Properties > ID. There's a button to filter the list: Enter text to search for, and press "Filter List" to reduce the list to just the items that have the entered text.
Image File Select an image file to use as the icon. This tool will save the path to that file, so it will be loaded from that location every time the menu is loaded. If you delete or move it, the tool will no longer be able to find it until you update this.
ARGB data Paste the hex encoded data into this box.
- cIconID string is a special unique ID for an existing vector icon in Editor. I've put a dropdown with the full list of icon IDs. It's the same id as shows up under Customize > Command Properties > ID. There's a button to filter the list: Enter text to search for, and press "Filter List" to reduce the list to just the items that have the entered text.
When you first install the tool it comes with four snippets:
One that sets the zoom level to 175%.
- It adds a button to the Add-on Tools:
Code: Select all
this.zoom = 175;
Startup Function is an example of a script that could run at startup, and has a private variable "counter".
Show Classic/Ribbon UI menu structure is the following script. It has no menu button assigned to it and outputs the Classic/Ribbon UI structure to the console:
Code: Select all
/************************************************************************
To see the actual Classic/Ribbon UI structure you may use the
following script:
************************************************************************/
function FancyMenuList(m, nLevel) {
var s = "";
for (var i = 0; i < nLevel; i++) s += " ";
var n = m.cName;
if (n == "") n = "-----"
console.println(s + n);
if (m.oChildren != null)
for (var i = 0; i < m.oChildren.length; i++)
FancyMenuList(m.oChildren[i], nLevel + 1);
}
var m = app.listMenuItems(); //to get list of items inside ClassicUI.MenuBar or inside the RibbonUI,
// also the optional cName parameter can be used to get items-list of certain menu/toolbar/tab
//var m = app.listToolbarButtons(); // to get list of items inside the Addon toolbar
for (var i = 0; i < m.length; i++) FancyMenuList(m[i], 0);Limitations
The tool will not work for any functions that require privileged functions.fixed v1.0- If a document is open when you change or add a menu item, when the document is closed that menu item may disappear until you restart PDF XChange.