JavaScript to save all documents (tabs) in window to one location

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

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

JavaScript to save all documents (tabs) in window to one location

Post by MedBooster »

JavaScript to save all documents (tabs) in window to one location (folder/file path)

Would anyone be up for the challenge?

You see, as previously mentioned (in other threads), sometimes "save all" works for "unsaved" opened documents, other times it doesn't, so this would really save some time.

Hmm... maybe a save as dialogue could appear for the 1st document, and then the rest could just automatically be saved to the same file path (folder) as the first?
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: 13150
Joined: Wed Jan 03, 2018 6:52 pm

Re: JavaScript to save all documents (tabs) in window to one location

Post by Daniel - PDF-XChange »

Hello, MedBooster

I expect that starting a "save as" action for all open documents could be possible, but I am not so sure that inheriting the selected location as the target folder would be. I wish you luck in your search with this. As per usual, I cannot help with writing new JS.

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
[email protected]
MedBooster
User
Posts: 1423
Joined: Mon Nov 15, 2021 8:38 pm

Re: JavaScript to save all documents (tabs) in window to one location

Post by MedBooster »

Master Mathew, any advice? Maybe you would consider making such a script for PDF-XCE?


I'm getting annoyed with such errors when batch saving multiple PDF-documents for the first time... I end up having to save each file manually

Half of the time I am able to just chose save all and I will be asked for each and I just have to press Enter a few times, that's easier, but a JavaScript could possibly work around this, right?
image.png
↑error from using save all with documents not saved yet (doesn't happen all the time, maybe 20% of the time
You do not have the required permissions to view the files attached to this post.
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
Vasyl - PDF-XChange
Site Admin
Posts: 2495
Joined: Thu Jun 30, 2005 4:11 pm

Re: JavaScript to save all documents (tabs) in window to one location

Post by Vasyl - PDF-XChange »

You see, as previously mentioned (in other threads), sometimes "save all" works for "unsaved" opened documents, other times it doesn't, so this would really save some time.
Do you mean this feature:
image.png
?

Does this one sometimes not work? If yes - can you explain how to reproduce the problem(s)?
You do not have the required permissions to view the files attached to this post.
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
Vasyl - PDF-XChange
Site Admin
Posts: 2495
Joined: Thu Jun 30, 2005 4:11 pm

Re: JavaScript to save all documents (tabs) in window to one location

Post by Vasyl - PDF-XChange »

It appears you are using an older version, as the current version shows which program locked the file and caused the AccessDenied error...
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
Mathew
User
Posts: 889
Joined: Thu Jun 19, 2014 7:30 pm

Re: JavaScript to save all documents (tabs) in window to one location

Post by Mathew »

MedBooster wrote: Fri Jan 17, 2025 10:45 am
Hmm... maybe a save as dialogue could appear for the 1st document, and then the rest could just automatically be saved to the same file path (folder) as the first?
Sorry I never got around to this until now - not sure if PXCE has already added something for this, but here's a script that, as suggested, will present a Save As dialog, and then save all the open documents to the same folder that you select to save to...

[Edit 4/29/2026] I combined the function of this tool with the showActiveDocuments tool -- I think that works better because one can select the documents to save to the same folder.

Adds a menu item "Save All to Folder" under File > Save As (ribbon UI) and File > Save To (Classic UI)
image.png
[Edit v1.1] I added a dialog at the end confirming how many files were saved, and if there were any errors:
image(1).png

Extract the zip file and save to the JavaScripts folder: viewtopic.php?p=196006#p196006
saveAllToFolder v1.1.zip

It's also translatable as of v1.1. Here are the translation strings:

Code: Select all

# Translation file (requires 1ang v1.0 or later)
# Domain for this translation file is "saveAllDocuments"
# Filename must be "translationData.saveAllDocuments.json" and saved in the JavaScripts folder

# It is not necessary for all strings to be included in every language,
#   but don't put an empty string "" for the translation, because that's what will be shown!
# This must be formatted as a JSON file except that:
#   lines starting with # and empty lines are stripped out before processing

# "Language" is three letter code as output from app.language
# "Original Text" is case sensitive!
#   Notice that the last item in a list does not allow a comma after it.
# Format:
#  "Language 1": {
#    "Original Text": "Translated Text in Language 1",
#    "Original Text 2": ["Translated Text 2 singular", "Translated Text 2 plural"]
#   },
#  "Language 2": {
#    "Original Text": "Translated Text in Language 2"
#   }

{
 "": {
     "Save All to Folder…": "",
     "New Document%1.pdf": "",
     "Saved %1 files with %2 errors.": "",
     "\nThere were errors saving the following files (see console output):\n%1\nDo you want to retry?": "",
     "New Document": "",
     "Save All to Folder": ""
 }
}
You do not have the required permissions to view the files attached to this post.
Last edited by Mathew on Thu Apr 30, 2026 12:28 am, edited 6 times in total.
User avatar
Sean - PDF-XChange
Site Admin
Posts: 1152
Joined: Wed Sep 14, 2016 5:42 pm

Re: JavaScript to save all documents (tabs) in window to one location

Post by Sean - PDF-XChange »

Hi Mathew,

That's great! Thanks so much for your help, as always.

Kind regards,
Sean Godley
Technical Writer
PDF-XChange Co LTD
Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623
MedBooster
User
Posts: 1423
Joined: Mon Nov 15, 2021 8:38 pm

Re: JavaScript to save all documents (tabs) in window to one location

Post by MedBooster »

Thank yoU! The other tool is great as well
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
Sean - PDF-XChange
Site Admin
Posts: 1152
Joined: Wed Sep 14, 2016 5:42 pm

Re: JavaScript to save all documents (tabs) in window to one location

Post by Sean - PDF-XChange »

:)
Sean Godley
Technical Writer
PDF-XChange Co LTD
Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623