Installation
To use the tool, extract the zip and save files in the Javascripts folder either in the application folder, or in %APPDATA%\Tracker Software\PDFXEditor\3.0\Javascripts
Restart PDF-XChange and it will add a tool to the Bookmarks ribbon or menu:
Usage
Click in the tool to open an extensive dialog: Choose whether to rename current bookmarks or add bookmarks
At the top, select whether to rename current bookmarks or add bookmarks for a page range.
Page range format is the same as the print dialog: Dash is inclusive range (10-20), comma separates ranges (1,5,10-12).
For PDF XChange build 393 or later, you can select which bookmarks to change using the … button.
Adding rename steps
On the left top, there are buttons to Add, move or delete individual naming steps. For PDF XChange versions before 387, there's also an 'Edit' button. Below that it lists the steps. Each 'step' can be a separate selected area, or piece of text, that is combined to make the new bookmark name.
Editing rename steps
Select a step from the list (and for versions before 387 then press 'Edit…'. Because PDF XChange versions before 387 didn't allow a script to know when you've selected a step, you must press the Edit button to update the fields on the right side.)
On the right side of the dialog are the options for this step. From the top:
- At the top is a preview of the text found in the currently selected region on the page.
Below that is the editable name for this step and a button to Select Region: Press this button to pick an area on the page. It should activate the rectangle tool for you to draw a rectangle, and shortly after you draw it, it should come back to this dialog, with the rectangle shown in green.
100% inside: To the right of this button is an option whether to only include text that is completely inside the picked area, or allow words to hang outside the rectangle slightly.
Anchor: The region selected can be anchored to the page corners, or edge midpoints, or center. This is so that if page sizes change slightly, the picked area still captures text in the same relative point to the anchor point.
White space: Select whether to strip out white space (spaces, tab, newline, etc) or white space and punctuation from the found text.
Word order: Because the arrangement of words in title blocks sometimes doesn't match the word order that is stored in the pdf, there's an option to sort the word order top to bottom of page, and/or right and left.
PV: To PreView what text is selected on different pages, use the < or > buttons to cycle through the currently selected bookmarks or page range.
Text: Optionally add text before or after the text that was found on the page. I included an implementation some of PXE's macros (sequence number, page, number of pages, page label, filename, date, and I added one that adds the previous bookmark name).
Transformations: The case can be changed to UPPER, lower, Initial Capitals, Title Case. Title Case capitalizes all words except a, an, the, for, and, nor, but, or, yet, so, as, at, by, for, in, of, on, per, pro, sub, thru, to, up, re, ca., vs., v., w/, w/o. It will do find and replace on the new name and can use a macro in the replacement text.
When all changes are ready, press Rename to run the tool. It can be a bit slow; there's a progress dialog in the lower right corner.
As of v0.5 the tool is translatable: If you want it in a language other than English, edit the translationData.bkmNameReg.json file to add translation for the English phrases. Post the translation file here and I'll include it in future revisions. For instructions on using the tool I made to help editing the translation files see viewtopic.php?p=186101#p186101 or for more information about 1ang.js see the post viewtopic.php?t=43253
Limitations
- Fixed v1.0
The tool does not generate bookmarks. It renames the current bookmarks. - Fixed PDF XChange build 393:
The tool renames all of the current bookmarks! - Because the only way for javascript to know where a bookmark points to is to activate that bookmark, the renaming can be a bit slow. I added a progress dialog.
- Fixed in build 387:
The dialog doesn't know when you picked a different step, so you must press "edit" after you pick a step or you'll be editing the previously selected step. This can be confusing.
- Done.
If the tool added bookmarks, and those bookmarks could be the same as those generated by PXE internally (so they update with added pages, etc) - If the tool could search the page for text in the bookmark (ie sheet number) and also add a link over this text.
For v1.0 I found a workaround to generating bookmarks: The script goes to the required location, then runs the built-in menu item app.execMenuItem('cmd.addBookmark', doc). It then has to figure out which bookmark was added, and change its name. It now just assembles a list of all the bookmarks before the bookmark is added, then compares by object to the list to find the new one.
Because there are so many different pieces in this tool, I've split out some of the utility functions to "xutils" that are in a separate file. I'll post info about that separately.