PDF-XCE JavaScript Index  SOLVED

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

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

Post Reply
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

PDF-XCE JavaScript Index  SOLVED

Post by MedBooster »

The 2nd reply is a great overview where the scripts are categorized into function. Check it out!

(new as of January 2025) To assign a keyboard shortcut to a script in the Javascripts folder that has a menu item
shortcut to JS-command directly in the script.
viewtopic.php?t=44574&sid=d302a72d9a19a ... 2e2761e6e4

2025 new JavaScript tools
[Tool] Change Case (Uppercase / Lowercase) SOLVED
viewtopic.php?p=189577#p189577

Many thanks to Mathew for making these tools for PDF-XCE

Change annotation colors tool
viewtopic.php?t=40404

[tool] change fonts in annotations
viewtopic.php?p=178656#p178656

javascript: custom menu item to Mirror (Flip) annotations SOLVED
viewtopic.php?t=39917

(alternative to the inbuilt tool)
Question: (Javascript?) script for adding page number to end of bookmark names
viewtopic.php?p=175299&hilit=tool#p175299

Hatch pattern tool SOLVED
viewtopic.php?p=175941&hilit=tool#p175941

Tool: Find and Replace text in markup
viewtopic.php?p=177460&hilit=tool#p177460

[tool] PDF tool to generate icon SOLVED
viewtopic.php?p=178337&hilit=tool#p178337

Create rectangles with rounded corners
viewtopic.php?p=178659#p178659

javascript: custom menu item to Mirror (Flip) annotations SOLVED
viewtopic.php?t=39917

Tool: Scale annotations by two reference lengths
viewtopic.php?p=175879&hilit=tool#p175879

Tool: Combine odd & even pages to single document SOLVED
viewtopic.php?p=173095&hilit=tool#p173095

Tool: Override dimension text
viewtopic.php?p=172526&hilit=tool#p172526

Tool to hide/show annotations SOLVED
viewtopic.php?p=170987&hilit=tool#p170987

Re: Flip Line Command
viewtopic.php?p=173669&hilit=tool#p173669

tool to rotate text
viewtopic.php?p=170364&hilit=tool#p170364

Recently added too:

Name Bookmarks based on text in area of page
viewtopic.php?t=42477

Combine text in Bookmarks generated from Page text
viewtopic.php?p=174993#p174993

'Nudge' Rotate markup by arbitrary increment
viewtopic.php?t=42851

A javascript tool for making scripts Multilingual
viewtopic.php?t=43253

Simple custom linetypes
viewtopic.php?t=43280

Delete multiple child bookmarks
viewtopic.php?p=184660#p184660

Merge comments in multiple pdf files
viewtopic.php?t=44263

rounded rectangles v0.4.zip viewtopic.php?t=41332&sid=749e0411b1143 ... a260c1c08c

Dynamic stamp
shop drawing review stamp - it has a dialog so that you can enter relevant information for the stamp before it's placed.
viewtopic.php?t=44637 (feel free to share your own stamps here)

Save without comments
viewtopic.php?t=44737
Last edited by MedBooster on Thu Jan 30, 2025 9:10 am, edited 10 times in total.
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10862
Joined: Wed Jan 03, 2018 6:52 pm

Re: Mathew's PDF-XCE JavaScripts

Post by Daniel - PDF-XChange »

Hello, MedBooster

Thank you very much for this, we had talked about highlighting this excellent work, but hadn't decided on where and how to do so just yet. For now, I have marked this post as a sticky item so it appears at the top of the list in this subforum.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 560
Joined: Thu Jun 19, 2014 7:30 pm

Re: Mathew's PDF-XCE JavaScripts

Post by Mathew »

Oh wow - thanks for making the list. :) [Edit] I decided to make a categorized list - may help if someone's looking for something in particular. The forum limits the number of links allowed in a post, so some of the links are just the URL.

For all the tools, if I make updates to them, I try to update the first post about them (at the top of the topic) with the most recent version. Also, I only test these tools on the most recent version of PDF XChange. If you are running an older version of PXCE the tools may not work.

Drawing tools
Markup Editing tools
Dimension Tools
Bookmark tools
Utility/File tools
  • Combine odd/even pages in two documents, with option to reverse the page order:
    viewtopic.php?t=40885
  • Synchronize page view between two documents
    viewtopic.php?t=45751
  • Merge comments in multiple pdf files
    viewtopic.php?t=44263
  • File Locking for multiple users (notifies if file is already open for editing by another user)
    viewtopic.php?t=44459
  • Save copy of PDF without comments
    forum.pdf-xchange.com/viewtopic.php?p=187923#p187923
  • Scale ACAD hatch pattern (PDF form) for use with the Hatch tool
    forum.pdf-xchange.com/viewtopic.php?p=173230#p173230
  • Tool to aid in editing translations (PDF form) for use with 1ang translation tool
    viewtopic.php?p=186101#p186101
  • Expand the page to show all comments (also can set Media box to the Trim box)
    forum.pdf-xchange.com/viewtopic.php?p=188981#p188981
  • Set the timeout between pencil annotations that are grouped as a single annotation
    forum.pdf-xchange.com/viewtopic.php?p=189538#p189538
  • Extract pages with markup (annotations) by selected authors
    viewtopic.php?t=45655

Javascript Library
These are scripts that help with other scripting, not tools in themselves.
  • Easier dynamic stamp dialogs.
    This also enables dynamic stamp colors, setting stamp properties, and running tools after the stamp has been placed.
    forum.pdf-xchange.com/viewtopic.php?t=45879
  • Tool to make icon stream for menu item icons (PDF form)
    forum.pdf-xchange.com/viewtopic.php?t=42029
  • A javascript tool for making scripts Multilingual (1ang.js)
    forum.pdf-xchange.com/viewtopic.php?t=43253
  • xutils Utility functions (xutil.setInterval, xutil.setTimeout, xutil.clearInterval, xutil.clearTimeout, xutil.getNewAnn, xutil.PXEmacro)
    forum.pdf-xchange.com/viewtopic.php?t=44731
  • RLE compression algorithm (xutil.decodeRLx, xutil.encodeRLx)
    forum.pdf-xchange.com/viewtopic.php?p=178285#p178285
Superceded/Not needed in current release
These are older tools that added functionality that was later added to PDF XChange.
  • Next/previous page without changing view:
    forum.pdf-xchange.com/viewtopic.php?p=167785#p167785
  • Find/replace text in markup:
    forum.pdf-xchange.com/viewtopic.php?t=41797
  • Rectangles with rounded corners:
    forum.pdf-xchange.com/viewtopic.php?p=175898#p175898
  • Bulk change fonts in markup
    forum.pdf-xchange.com/viewtopic.php?t=42180
  • Set the crop box bounds to those of one of the other boxes (Art, Bleed, BBox, Trim)
    forum.pdf-xchange.com/viewtopic.php?p=188949#p188949
  • Delete multiple child bookmarks
    forum.pdf-xchange.com/viewtopic.php?p=184660#p184660
Last edited by Mathew on Thu Apr 03, 2025 11:03 pm, edited 25 times in total.
User avatar
rakunavi
User
Posts: 1635
Joined: Sat Sep 11, 2021 5:04 am

Re: Mathew's PDF-XCE JavaScripts

Post by rakunavi »

Hello all,

Originally created by benep, this script, recently updated by Mathew, is also indispensable to me.

I would like to thank Mathew and benep for their great contribution.

Best regards,
rakunavi
TOP desires for PDFXCE
forum.pdf-xchange.com/viewtopic.php?t=39665 LassoTool
forum.pdf-xchange.com/viewtopic.php?t=38554 CmtGarbled
forum.pdf-xchange.com/viewtopic.php?t=37353 FulScrMultiMon
forum.pdf-xchange.com/viewtopic.php?t=41002 DisableTouchSelect
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19777
Joined: Mon Jan 12, 2009 8:07 am
Contact:

Re: Mathew's PDF-XCE JavaScripts

Post by Stefan - PDF-XChange »

Hello MedBooster, Mathew, rakunavi, and all,

Indeed Many thanks to Mathew and Banep, as well as you Rakunavi, and MedBooster for making this topic as well as anyone else posting in the forums for all the great contributions you are all making!
I am sure that they all help in getting our products even better!

Kind regards,
Stefan
User avatar
PHK
User
Posts: 1387
Joined: Tue Nov 24, 2020 4:02 pm

Re: Mathew's PDF-XCE JavaScripts

Post by PHK »

@Mathew. Great work and also a shoutout to MedBooster for compiling the extensive list!

But Mathew, are you willing to tackle more related work? For instance, Users sometimes ask for a one-step function that 'chains' a given sequence of uses of Tools. I don't think I know how to do this, do you? Would you?
All best,

FringePhil
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Mathew's PDF-XCE JavaScripts

Post by MedBooster »

Since we're asking questions...
all these scripts only affect comments(annotations) –
JavaScript is not able to affect base content in PDF-XCE, is that right
:)
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
Mathew
User
Posts: 560
Joined: Thu Jun 19, 2014 7:30 pm

Re: Mathew's PDF-XCE JavaScripts

Post by Mathew »

MedBooster wrote: Mon Apr 22, 2024 7:30 pm
JavaScript is not able to affect base content in PDF-XCE, is that right
Generally yes. For a while I was dreaming about the possibility of an extension of JavaScript in PXE to allow that, but that's too heavy a lift for me.
  • There's a very limited ability to read text from base content (doc.getPageNthWord()), but not to change it.
  • Pretty broad functionality for adding/deleting/responding to and working with fields
  • Add and remove scripts, and attach scripts to various elements (bookmarks, links, fields, documents, media)
  • There are functions to work with data objects attached to the pdf that I've never played with
  • I've never touched any of the media related functions, key certificates or the functions related to remote procedure calls
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10862
Joined: Wed Jan 03, 2018 6:52 pm

Re: Mathew's PDF-XCE JavaScripts

Post by Daniel - PDF-XChange »

Hello,

As Matthew says, Base content is pretty well locked down in PDF as a whole, it is not a limitation specific to our software.
JS can be used to create new base content (essentially by creating comments and flattening them, as Matthew's hatching tool works), and it may be possible to use the "redact" tool via JS, allowing a pretty heavy handed method of deleting base content (and anything else nearby) via JS, but direct editing, such as locating an image, or shape, or text, and modifying it, are not possible.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 560
Joined: Thu Jun 19, 2014 7:30 pm

Re: Mathew's PDF-XCE JavaScripts

Post by Mathew »

PHK wrote: Mon Apr 22, 2024 1:36 pm are you willing to tackle more related work?
@FringePhil sorry I missed this question.
Short answer: No.
Longer answer: I usually make the tools to do something I run into often that's not yet (or ever) available in the software. I share them in the hope that others find them useful too. Because this is essentially a hobby to me, I don't have time to take on specific projects.
User avatar
PHK
User
Posts: 1387
Joined: Tue Nov 24, 2020 4:02 pm

Re: Mathew's PDF-XCE JavaScripts

Post by PHK »

Mathew wrote: Tue Jun 18, 2024 9:39 pm
PHK wrote: Mon Apr 22, 2024 1:36 pm are you willing to tackle more related work?
@FringePhil sorry I missed this question.
Short answer: No.
Longer answer: I usually make the tools to do something I run into often that's not yet (or ever) available in the software. I share them in the hope that others find them useful too. Because this is essentially a hobby to me, I don't have time to take on specific projects.
No problem; thanks!
All best,

FringePhil
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10862
Joined: Wed Jan 03, 2018 6:52 pm

Mathew's PDF-XCE JavaScripts

Post by Daniel - PDF-XChange »

:)
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2444
Joined: Thu Jun 30, 2005 4:11 pm

Re: Mathew's PDF-XCE JavaScripts

Post by Vasyl - PDF-XChange »

Hi Guys.

To all JavaScript users: in the latest build we improved/extended the app.addMenuItem(), app.addSubMenu() and app.addToolButton() features.
Here is sample script that shows how to add custom Tabs/Groups/Menus/Buttons to the Ribbon/Classic UI. The result of this script is:

image.png

The feature is also related to the following topics:

viewtopic.php?t=37429
viewtopic.php?t=40887
viewtopic.php?t=42808

HTH.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
User avatar
Roman - Tracker Supp
Site Admin
Posts: 331
Joined: Sun Nov 21, 2004 3:19 pm

Re: Mathew's PDF-XCE JavaScripts

Post by Roman - Tracker Supp »

In the next 10.5 release of the Editor we are planning PDF-XChange specific extensions to the JavaScript API (mostly inspired by Mathew :D ).

app.execDialog:
  • Selection tracking for intermediate items in "hier_list_box".
  • An option to disable sorting in "hier_list_box".
  • Multi-selection in "list_box" and "hier_list_box"
A sample code is available here.

app.setTimeOut and app.setInterval accept a callable JavaScript object. E.g. the following code will work:

Code: Select all

app.setTimeOut(() => console.println('Hi, future!'), 1000);
app.timeOut method returns a promise to facilitate asynchronous programming:

Code: Select all

async function iterate(count, timeout)
{
    for (let i = 0; i < count; ++i)
    {
        await app.timeOut(timeout);
        console.println(`Iteration ${i}`);
    }
}
iterate(10, 1000).then(() => console.println('Done!'), () => console.println('Aborted!'));
console.println('Started!');

Code: Select all

async function* generate(count, timeout)
{
    for (let i = 0; i < count; ++i)
        await app.timeOut(timeout), yield i;
}
async function generations(count) 
{
    for await (const i of generate(count, 1000))
        console.println(`Generation ${i}`);
}

generations(10);
Post Reply