[js library] utilities for scripting  SOLVED

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Mathew
User
Posts: 600
Joined: Thu Jun 19, 2014 7:30 pm

[js library] utilities for scripting  SOLVED

Post by Mathew »

I use these utility functions quite a lot in other scripts. I've tried to document them within the code, so I won't repeat here. The color utilities I've been using for quite a while but didn't get around to posting the source here until v2. It includes a color picker that makes use of the undocumented 'image' and 'link_text' types in dialogs.

The timeout and interval functions are not needed as of the 10.5 release of PDF-XChange.
The PXEmacro class is mostly covered by the new util.expandMacros method as of the 10.6 release of PDF-XChange https://www.pdf-xchange.com/product/pdf ... 10-6-0-396

Initially I was planning to minify the script, but because this is all loaded locally, I didn't see a need.
xutil v0.7.zip
xutil.colorUtils v2.1.zip
This is a pdf with documentation (output by jsDoc):
xutil 2025-07-03.pdf
xutil.addBookmark
  • Add a bookmark that uses built-in bookmark properties at current page/zoom/position (ie without the limitations of bookmark.setAction())
    Uses a saved array of bookmarks and .includes() to find which bookmark was added.
xutil.setInterval
xutil.setTimeout Note that capitalization matches javascript in browsers (the built-in app.setTimeOut() capitalizes 'Out'.)
  • These extend the built in app methods to allow one to pass functions. I find this much easier to work with because I can use closures. Instead of returning an object, they return an integer greater than zero on success.
xutil.clearInterval
xutil.clearTimeout
  • Functions to clear the interval or timeout set with the above functions.
xutil.getNewAnn
  • Get an annotation as soon as it's drawn
xutil.PXEmacro
  • Minimal PDF-XChange macros class for javascript
xutil.ClrUtx
  • Class for color utilities I have used in quite a few scripts. From v2 onwards, it has a dialog that includes color images for a color picker (previously it was limited to just using the color names in a drop-down list). It's documented in the code, but I've also output the jsDoc as a pdf.
You do not have the required permissions to view the files attached to this post.
Last edited by Mathew on Thu Jul 03, 2025 11:50 pm, edited 17 times in total.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: [javascript] utilities for scripting

Post by Stefan - PDF-XChange »

Hello Mathew,

Many thanks for sharing those utilities you've prepared with other users here in the forums!

Kind regards,
Stefan
Mathew
User
Posts: 600
Joined: Thu Jun 19, 2014 7:30 pm

Re: [javascript] utilities for scripting

Post by Mathew »

I changed the parameters that get sent to the timeout and interval functions. Now 'this' (the current doc) is sent if no additional args are supplied, otherwise, only the additional args.
xutil v0.4.zip
You do not have the required permissions to view the files attached to this post.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

[javascript] utilities for scripting

Post by Stefan - PDF-XChange »

:)
Mathew
User
Posts: 600
Joined: Thu Jun 19, 2014 7:30 pm

Re: [js library] utilities for scripting

Post by Mathew »

Adding xutil.ClrUtx source code to the first post above.
xutil.colorUtils v2.1.zip
version history
* v2.1 2025-07-02 fix some duplicated color names; add hideLinks parameter to color picker; fix errors when making dialog if color is null; code cleanup in main loop; slight change to method of finding nearest color
* v2.0 2025-06-30 add color box picker option; add color boxes to editColrNames; add new method editCustomColors; lint cleanup; add .useHex property; document code; standard colors rearranged and based on @mCHSNUg5Pz8cPap forum post viewtopic.php?t=46178
* v1.2 2025-03-30 make equal a static property so can use xutil.ClrUtx.equal()
* v1.1 2024-11-18 add noSave parameter to editColrNames()
* v1.0.1 2024-11-18 check if supplied color string undefined in colFromStr
* v1.0 2024-09-18 revised to separate xutil, added own persistent global, added translation, make color name based on nearby colors
* v0.1 part of change colors tool

xutils is also updated to v0.7
version history
* v0.7 2025-04-04 PXEmacro revisions, getNewAnn revisions, added xutil.addBookmark()
* v0.6 2025-03-31 fix alphabetize function; add methods dealphabetize, deromanize, fromNumberType
* v0.5 2024-12-12 fix bugs and add return function for cancel in getNewAnn(), add parameter to setTimeout so can request an ID (makes dealing with cancelling timeouts in running intervals easier)
* v0.4 2024-12-03 changed parameters supplied to timeout and interval return functions, code cleanup
* v0.3 2024-05-08 added xutil.PXEmacro()
* v0.2 2024-05-03 added xutil.getNewAnn()
* v0.1.1 2024-04-28 added _XUTIL_DEBUG_ option
* v0.1.0 2024-04-12
You do not have the required permissions to view the files attached to this post.