Save without comments [Suggestion]
Moderators: Daniel - PDF-XChange, PDF-XChange Support, Paul - PDF-XChange, Vasyl - PDF-XChange, Chris - PDF-XChange, Sean - Tracker, Ivan - Tracker Software, Stefan - PDF-XChange
-
- User
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Save without comments [Suggestion]
Edit:
you can print without comments (annotations), but you can't save without comments. Would you consider adding this as a function/button you also can bind a keyboard shortcut to? This would save some steps in not having to delete comments and keep working on the document WITH comments after having saved it WITHOUT comments. See what I mean?
Sure you can print to PDF without comments... but would really all comments and annotations
disadvantage with print to PDF :
takes more time to process document
and when you print to PDF using PDF Xchange lite the pages just become images basically, with the text as paths instead of editable text it seems.
Simple save as prompt with menu item – you stay in the active document while a new one without comments is saved in the chosen folder.you can print without comments (annotations), but you can't save without comments. Would you consider adding this as a function/button you also can bind a keyboard shortcut to? This would save some steps in not having to delete comments and keep working on the document WITH comments after having saved it WITHOUT comments. See what I mean?
Sure you can print to PDF without comments... but would really all comments and annotations
disadvantage with print to PDF :
takes more time to process document
and when you print to PDF using PDF Xchange lite the pages just become images basically, with the text as paths instead of editable text it seems.
Last edited by MedBooster on Tue Dec 10, 2024 10:28 am, edited 1 time 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
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
- Stefan - PDF-XChange
- Site Admin
- Posts: 19285
- Joined: Mon Jan 12, 2009 8:07 am
- Contact:
Re: Save without comments [Suggestion]
Hello MedBooster,
When printing you are creating a 'permanent' version of your file (whether on paper on in other file format) that might benefit from you not having the comments in it.
But when you do have the file already at hand - you can easily open the comments pane and remove those comments if that is the desired action. It is a few clicks at most, and given that this does not seem like a task the majority of people would do, and that I am not aware of any other tool offering "Save without comments" as a command - that I do not believe this would warrant a specific command for it.
Maybe you can add a custom tool button that would remove all your comments and launch a save as operation for you in a single click?
Kind regards,
Stefan
When printing you are creating a 'permanent' version of your file (whether on paper on in other file format) that might benefit from you not having the comments in it.
But when you do have the file already at hand - you can easily open the comments pane and remove those comments if that is the desired action. It is a few clicks at most, and given that this does not seem like a task the majority of people would do, and that I am not aware of any other tool offering "Save without comments" as a command - that I do not believe this would warrant a specific command for it.
Maybe you can add a custom tool button that would remove all your comments and launch a save as operation for you in a single click?
Kind regards,
Stefan
-
- User
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Re: Save without comments [Suggestion]
Tracker Supp-Stefan wrote: ↑Tue Dec 03, 2024 12:55 pm Maybe you can add a custom tool button that would remove all your comments and launch a save as operation for you in a single click?
This sounds like a good option
If you just remember to save the file with annotations first, and then have the new document...
Maybe you could link to the manual or explain please? (How to make a "custom tool button"?)
So if it were possible to make a custom tool which...
1) save current PDF to existing file path
2) delete all annotations/comments
3) *save as* (new file path)
4) open the new file path?
Or maybe during the steps it would be smart to use a duplicate PDF function instead.
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
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
- Stefan - PDF-XChange
- Site Admin
- Posts: 19285
- Joined: Mon Jan 12, 2009 8:07 am
- Contact:
Re: Save without comments [Suggestion]
Hello MedBooster,
You will need the "addMenuItem, addSubMenu, addToolButton" in your JS dependng on where you want the tool to appear, and Mathew here has a good example on how it is to be done:
viewtopic.php?p=186932#p186932
Kind regards,
Stefan
You will need the "addMenuItem, addSubMenu, addToolButton" in your JS dependng on where you want the tool to appear, and Mathew here has a good example on how it is to be done:
viewtopic.php?p=186932#p186932
Kind regards,
Stefan
Re: Save without comments [Suggestion]
This could work thus (I didn't add the menu things - plenty of examples how to do that). A few functions require elevated privilege and there's no way around the security warning AFAIK):MedBooster wrote: ↑Tue Dec 03, 2024 2:03 pm So if it were possible to make a custom tool which...
1) save current PDF to existing file path
2) delete all annotations/comments
3) *save as* (new file path)
4) open the new file path?
Code: Select all
/** script to save a copy of document without any annotations
*
* @param doc - the document to save a copy of
* @param addSuffx - additional suffix text to insert before .pdf
* @param closeNewDoc - true to close the new document after deleting all annotations
**/
var saveWithoutAnnots = app.trustedFunction( (doc, addSuffx = '[clean]', closeNewDoc = false) => {
// save current PDF to existing file path
app.execMenuItem('Save', doc);
// *save as* (new file path)
// get the old file path so can open it later
const oldPath = doc.path;
// new path name
const newPath = oldPath.replace(/(\.pdf)$/i, `${addSuffx}$1`);
// the functions app.browseForDoc and doc.saveAs both require elevated privilege
app.beginPriv();
// first need to get a path
let savePath = app.browseForDoc({bSave: true, cFilenameInit: newPath});
if (!savePath) return; // user cancelled
// delete annots after getting the savePath in case user cancels
// delete all annotations/comments
for (let a of doc.getAnnots()) {
a.destroy();
}
// save it as this new path
doc.saveAs({cPath: savePath.cPath, cFS: savePath.cFS, bCopy: false, bPromptToOverwrite: false});
app.endPriv();
// close the clean document
if (closeNewDoc) doc.closeDoc(true);
// open the new file path?
// the currently open file is now the one without annotations
// open the previous file and return it
return app.openDoc({cPath: oldPath})
});
saveWithoutAnnots(this);
However, I think a better approach would be to make a copy of the file first, then delete the comments in it (ie move step (2) to the end). app.newDoc just makes a blank document that you'd then need to copy pages into, etc.. so you need to open this copy. The benefits of this approach are:
- It doesn't destroy the undo history in your original document
- You can open and process the 'clean' document hidden if you don't want to leave it open, so it acts more like a "Save Copy Without Comments" may be expected to behave.
- If something goes wrong along the way you haven't messed up your original document
[edited to fix a bug]
Code: Select all
/** script to save a copy of document without any annotations
*
* @param doc - the document to save a copy of
* @param closeNewDoc - true to close the new document after deleting all annotations (default false)
* @param addSuffx - optional suffix text to insert before .pdf (default '[clean]')
**/
var saveWithoutAnnots = app.trustedFunction( (doc, closeNewDoc = false, addSuffx = '[clean]') => {
// get the old file path
const oldPath = doc.path;
// new path name
const newPath = oldPath.replace(/(\.pdf)$/i, `${addSuffx}$1`);
// the functions app.browseForDoc and doc.saveAs both require elevated privilege
app.beginPriv();
// first need to get a path
let savePath = app.browseForDoc({bSave: true, cFilenameInit: newPath});
// maybe user cancelled
if (!savePath) return;
// *save as* (new file path)
// save *copy* of current PDF to new file path bCopy: true
doc.saveAs({cPath: savePath.cPath, cFS: savePath.cFS, bCopy: true, bPromptToOverwrite: false});
app.endPriv();
// open new copy - if closeNewDoc then open it hidden
// this needs to be enclosed in try because if user cancelles the security warning, then system throws an error
const openDoc = (...params) => {
try {
return app.openDoc(...params);
} catch(e) {
console.println(e);
return;
}
};
const newCopyDoc = openDoc({ cPath: savePath.cPath, cFS: savePath.cFS, bHidden: closeNewDoc });
// maybe a problem opening the new document?
if (!newCopyDoc) {
console.println(`Could not open file to delete the annotations in "${savePath.cPath}".`);
return;
}
// delete all annotations/comments
for (let a of newCopyDoc.getAnnots()) {
a.destroy();
}
// save and if closeNewDoc close it
app.execMenuItem('Save', newCopyDoc);
if (closeNewDoc) newCopyDoc.closeDoc(true);
// return original file
return doc;
});
saveWithoutAnnots(this, true);
- Daniel - PDF-XChange
- Site Admin
- Posts: 10158
- Joined: Wed Jan 03, 2018 6:52 pm
Re: Save without comments [Suggestion]
Hello,
I dont see why there is a need for a special custom tool to perform this. The "Save as" action itself will keep the newly saved copy of the file open after saving.
In practice, all you need to do is:
1. Save normal file (comments still present)
2. Open comments pane (Ctrl_M)
3. in comments pane, press Select all (Ctrl+A) > Delete
4. Save as (Ctrl+Shift+S) choose a new name or location to save the "non-commented" version.
Now you have the non commented version open, and can carry on with your work.
Kind regards,
I dont see why there is a need for a special custom tool to perform this. The "Save as" action itself will keep the newly saved copy of the file open after saving.
In practice, all you need to do is:
1. Save normal file (comments still present)
2. Open comments pane (Ctrl_M)
3. in comments pane, press Select all (Ctrl+A) > Delete
4. Save as (Ctrl+Shift+S) choose a new name or location to save the "non-commented" version.
Now you have the non commented version open, and can carry on with your work.
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
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
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Re: Save without comments [Suggestion]
Thank you,
Mathew
Hello Daniel, yes I know how to do it step-by-step, this is just something I do a lot... so as mentioned it would be nice to do it in one click
Similarly to how you can print without annotations(comments) and keep working on your document,
if you follow the steps you mentioned, you will have to open back up
If the JavaScript is one button, and you could make it also for example add NoCom to the beginning of the filename, this would save some time.
And as opposed to deleting comments, and then using save as, with a javascript like this you would still be in the original document, and you can move to the next one if you are doing this to many documents at once
note to self: maybe I should make Mathew's JavaScript also save the document before it saves another copy without comments.
Mathew
Hello Daniel, yes I know how to do it step-by-step, this is just something I do a lot... so as mentioned it would be nice to do it in one click
Similarly to how you can print without annotations(comments) and keep working on your document,
if you follow the steps you mentioned, you will have to open back up
If the JavaScript is one button, and you could make it also for example add NoCom to the beginning of the filename, this would save some time.
And as opposed to deleting comments, and then using save as, with a javascript like this you would still be in the original document, and you can move to the next one if you are doing this to many documents at once
note to self: maybe I should make Mathew's JavaScript also save the document before it saves another copy without comments.
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
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
- Stefan - PDF-XChange
- Site Admin
- Posts: 19285
- Joined: Mon Jan 12, 2009 8:07 am
- Contact:
Re: Save without comments [Suggestion]
Hello MedBooster,
SaveAs when called through JS code can do a "Save as copy", however it does require elevated privileges so probably won't work through the toolbar button - as Mathew advised, there's no way to circumvent these restrictions.
Kind regards,
Stefan
SaveAs when called through JS code can do a "Save as copy", however it does require elevated privileges so probably won't work through the toolbar button - as Mathew advised, there's no way to circumvent these restrictions.
Kind regards,
Stefan
Re: Save without comments [Suggestion]
The second script leaves you in the original document - makes most sense to me. If you want it to just overwrite a "no comment" version without a "Save as" dialog, it becomes a simpler script: no need for browseForDoc(). Modify lines 14-22:MedBooster wrote: ↑Fri Dec 06, 2024 11:53 am If the JavaScript is one button, and you could make it also for example add NoCom to the beginning of the filename, this would save some time.
note to self: maybe I should make Mathew's JavaScript also save the document before it saves another copy without comments.
Code: Select all
app.beginPriv();
// save *copy* of current PDF to new file path
doc.saveAs({cPath: newPath, cFS: '', bCopy: true, bPromptToOverwrite: false});
app.endPriv();
Code: Select all
const newPath = oldPath.replace(/\/([^\/]+\.pdf)$/i, `/${addSuffx}$1`);
- Daniel - PDF-XChange
- Site Admin
- Posts: 10158
- Joined: Wed Jan 03, 2018 6:52 pm
Save without comments [Suggestion]
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
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
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Re: Save without comments [Suggestion]
Wow... how difficult it is to make a script a menu item... I tried looking at other scripts but...
Edit: the dialogue opens, but when you save as... no PDF is actually saved there weird....
*edit – improvements:
Edit: the dialogue opens, but when you save as... no PDF is actually saved there weird....
Code: Select all
// Add tool button for managing annotations
app.addToolButton({
cName: "removeSelectedAnnotations",
cLabel: "Remove Selected Annotations",
cTooltext: "Open a dialog to save a copy without annotations.",
cExec: "saveDocDialog.startDialog(this)" // Pass the active document (this) explicitly
});
// Dialog for saving the document without annotations
const saveDocDialog = {
description: {
name: "Save Document Without Annotations",
width: 380,
elements: [
{
type: "static_text",
name: "Save a copy of the document without annotations.",
alignment: "align_center",
width: 380
},
{
type: "checkbox",
name: "closeNewDoc",
label: "Close the new document after saving",
value: 0 // Default to unchecked
},
{
type: "edit_text",
name: "addSuffix",
label: "Suffix for new filename:",
value: "[clean]"
},
{
type: "ok_cancel",
ok_name: "Save",
cancel_name: "Cancel"
}
]
},
initialize: function (dialog) {
const initialData = {
closeNewDoc: 0,
addSuffix: "[clean]"
};
dialog.load(initialData); // Load initial dialog data
},
commit: function (dialog) {
const results = dialog.store(); // Retrieve dialog input values
const closeNewDoc = results["closeNewDoc"] === 1; // Checkbox value
const addSuffix = results["addSuffix"];
// Ensure document context is available
if (this.doc) {
saveWithoutAnnots(this.doc, closeNewDoc, addSuffix); // Pass the document reference
} else {
app.alert("No active document found to process annotations.");
}
},
startDialog: function (doc) {
if (!doc) {
app.alert("No active document found. Open a document before using this tool.");
return;
}
this.doc = doc; // Store the document reference
app.execDialog(this); // Execute the dialog
}
};
// Function to Save Without Annotations
var saveWithoutAnnots = app.trustedFunction((doc, closeNewDoc = false, addSuffix = '[clean]') => {
if (!doc) {
console.println("Error: No document context provided.");
return;
}
const oldPath = doc.path;
const newPath = oldPath.replace(/(\.pdf)$/i, `${addSuffix}$1`);
app.beginPriv();
try {
let savePath = app.browseForDoc({ bSave: true, cFilenameInit: newPath });
if (!savePath) return; // User canceled
doc.saveAs({ cPath: savePath, bCopy: true });
const newCopyDoc = app.openDoc({ cPath: savePath, bHidden: closeNewDoc });
if (!newCopyDoc) {
console.println(`Could not open file to delete the annotations in "${savePath}".`);
return;
}
// Delete all annotations/comments
const annots = newCopyDoc.getAnnots();
if (annots) {
for (let i = annots.length - 1; i >= 0; i--) {
annots[i].destroy();
}
}
// Save and close new document if required
newCopyDoc.saveAs();
if (closeNewDoc) newCopyDoc.closeDoc(true);
} catch (e) {
console.println(`Error saving document without annotations: ${e}`);
} finally {
app.endPriv();
}
return doc;
});
*edit – improvements:
Code: Select all
// Add tool button for managing annotations
app.addToolButton({
cName: "removeSelectedAnnotations",
cLabel: "Remove Selected Annotations",
cTooltext: "Open a dialog to save a copy without annotations.",
cExec: "saveDocDialog.startDialog(this)" // Pass the active document (this) explicitly
});
// Dialog for saving the document without annotations
const saveDocDialog = {
description: {
name: "Save Document Without Annotations",
width: 380,
elements: [
{
type: "static_text",
name: "Save a copy of the document without annotations.",
alignment: "align_center",
width: 380
},
{
type: "checkbox",
name: "closeNewDoc",
label: "Close the new document after saving",
value: 0 // Default to unchecked
},
{
type: "edit_text",
name: "addSuffix",
label: "Suffix for new filename:",
value: "[clean]"
},
{
type: "ok_cancel",
ok_name: "Save",
cancel_name: "Cancel"
}
]
},
initialize: function (dialog) {
const initialData = {
closeNewDoc: 0,
addSuffix: "[clean]"
};
dialog.load(initialData); // Load initial dialog data
},
commit: function (dialog) {
const results = dialog.store(); // Retrieve dialog input values
const closeNewDoc = results["closeNewDoc"] === 1; // Checkbox value
const addSuffix = results["addSuffix"];
// Ensure document context is available
if (this.doc) {
saveWithoutAnnots(this.doc, closeNewDoc, addSuffix); // Pass the document reference
} else {
app.alert("No active document found to process annotations.");
}
},
startDialog: function (doc) {
if (!doc) {
app.alert("No active document found. Open a document before using this tool.");
return;
}
this.doc = doc; // Store the document reference
app.execDialog(this); // Execute the dialog
}
};
// Function to Save Without Annotations
var saveWithoutAnnots = app.trustedFunction((doc, closeNewDoc = false, addSuffix = '[clean]') => {
if (!doc) {
console.println("Error: No document context provided.");
return;
}
const oldPath = doc.path;
const newPath = oldPath.replace(/(\.pdf)$/i, `${addSuffix}$1`);
app.beginPriv();
try {
let savePath = app.browseForDoc({ bSave: true, cFilenameInit: newPath });
if (!savePath) {
console.println("Operation canceled by the user.");
return;
}
// Save a copy of the document
doc.saveAs({ cPath: savePath, bCopy: true });
// Open the new document
const newCopyDoc = app.openDoc({ cPath: savePath, bHidden: closeNewDoc });
if (!newCopyDoc) {
console.println(`Could not open the file at "${savePath}".`);
return;
}
// Remove annotations
const annots = newCopyDoc.getAnnots();
if (annots) {
for (let i = annots.length - 1; i >= 0; i--) {
annots[i].destroy();
}
}
// Save and optionally close
newCopyDoc.saveAs();
if (closeNewDoc) newCopyDoc.closeDoc(true);
} catch (e) {
console.println(`Error during saveWithoutAnnots execution: ${e}`);
} finally {
app.endPriv();
}
return doc;
});
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
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
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Re: Save without comments [Suggestion]
This is better, no overambitious dialogue, just straight to a "save as" file-explorer-window'''
but still... when you save it no PDF seems to be found in the given folder....
(none at all, not even one with comments intact.
edit: I just tried the script again just in the Javascript console and I am getting this error...
where do you disable this security setting?
Error during save operation: NotAllowedError: Security settings prevent access to this property or method.
Which security settings is this about?
but still... when you save it no PDF seems to be found in the given folder....
(none at all, not even one with comments intact.
Code: Select all
// Add tool button for managing annotations
app.addToolButton({
cName: "removeSelectedAnnotations",
cLabel: "Remove Selected Annotations",
cTooltext: "Save a copy without annotations.",
cExec: "saveDocWithoutAnnotations(this)" // Trigger the save directly without dialog
});
// Function to Save Without Annotations
var saveDocWithoutAnnotations = app.trustedFunction((doc) => {
if (!doc) {
app.alert("No active document found. Open a document before using this tool.");
return;
}
// Set up the path for the new file, appending a suffix to the original name
const oldPath = doc.path;
const newPath = oldPath.replace(/(\.pdf)$/i, "[clean]$1"); // Append [clean] suffix
try {
app.beginPriv();
// Prompt the user to choose a save location
let savePath = app.browseForDoc({ bSave: true, cFilenameInit: newPath });
if (!savePath) {
console.println("Operation canceled by the user.");
return;
}
// Save a copy of the document
doc.saveAs({ cPath: savePath, bCopy: true });
// Open the new document and remove annotations
const newCopyDoc = app.openDoc({ cPath: savePath, bHidden: true });
if (!newCopyDoc) {
console.println(`Could not open the file at "${savePath}".`);
return;
}
// Remove annotations from the new document
const annots = newCopyDoc.getAnnots();
if (annots) {
for (let i = annots.length - 1; i >= 0; i--) {
annots[i].destroy();
}
}
// Save the document after removing annotations
newCopyDoc.saveAs();
newCopyDoc.closeDoc(true); // Optionally close the new document
} catch (e) {
console.println(`Error during save operation: ${e}`);
} finally {
app.endPriv();
}
});
edit: I just tried the script again just in the Javascript console and I am getting this error...
where do you disable this security setting?
Error during save operation: NotAllowedError: Security settings prevent access to this property or method.
Which security settings is this about?
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
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
Re: Save without comments [Suggestion]
You need to provide parameters to newCopyDoc.saveAs(); or you can do as I did and just use the built-in save app.execMenuItem('Save', newCopyDoc);
You made life hard on yourself: Simplest would have been to take my script, delete the last line, and add the menu stuff at the beginning:
Code: Select all
// Add tool button for managing annotations
app.addToolButton({
cName: "saveNoAnnots",
cLabel: "Save NA",
cTooltext: "Open a dialog to save a copy without annotations.",
cExec: "saveWithoutAnnots(this, true);" // Pass the active document (this) explicitly
});
/** script to save a copy of document without any annotations
*
* @param doc - the document to save a copy of
* @param closeNewDoc - true to close the new document after deleting all annotations (default false)
* @param addSuffx - optional suffix text to insert before .pdf (default '[clean]')
**/
var saveWithoutAnnots = app.trustedFunction( (doc, closeNewDoc = false, addSuffx = '[clean]') => {
// get the old file path
const oldPath = doc.path;
// new path name
const newPath = oldPath.replace(/(\.pdf)$/i, `${addSuffx}$1`);
// the functions app.browseForDoc and doc.saveAs both require elevated privilege
app.beginPriv();
// first need to get a path
let savePath = app.browseForDoc({bSave: true, cFilenameInit: newPath});
// maybe user cancelled
if (!savePath) return;
// *save as* (new file path)
// save *copy* of current PDF to new file path bCopy: true
doc.saveAs({cPath: savePath.cPath, cFS: savePath.cFS, bCopy: true, bPromptToOverwrite: false});
app.endPriv();
// open new copy - if closeNewDoc then open it hidden
// this needs to be enclosed in try because if user cancelles the security warning, then system throws an error
const openDoc = (...params) => {
try {
return app.openDoc(...params);
} catch(e) {
console.println(e);
return;
}
};
const newCopyDoc = openDoc({ cPath: savePath.cPath, cFS: savePath.cFS, bHidden: closeNewDoc });
// maybe a problem opening the new document?
if (!newCopyDoc) {
console.println(`Could not open file to delete the annotations in "${savePath.cPath}".`);
return;
}
// delete all annotations/comments
for (let a of newCopyDoc.getAnnots()) {
a.destroy();
}
// save and if closeNewDoc close it
app.execMenuItem('Save', newCopyDoc);
if (closeNewDoc) newCopyDoc.closeDoc(true);
// return original file
return doc;
});
-
- User
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Re: Save without comments [Suggestion]
Amaziing now it works (with no security errors)
The error I sent above was from just running it in the console: the *edit – improvements:
maybe not how you are supposed to run it though...
(the tool attached above which is the script you sent works though!) – for the same file in question
PS:
how do you zip javascript scripts to share? For some reason .js is an invalid file format to share on the forum... and WinRar is unable to zip a javascript file it seems...
I guess this website is an option...
https://www.ezyzip.com/convert-js-to-zip.html
thank you for the fix... I am decent with autohotkey, but JavaScript is something else... (but I like learning about it) Oh and thank you for adding headings in your scripts explaining what each part is for...
edit:
some ideas maybe I'll try and add it later
1) toggled (checkbox) to open the clean document in PDF-XCE (but not closing the original document tab)
2) toggles to remove only certain types of annotations and not all (all could be on by default and you could de-toggle the ones you want to keep
a) textboxes
b) shapes
c) stamps/images
d) highlights
The error I sent above was from just running it in the console: the *edit – improvements:
maybe not how you are supposed to run it though...
(the tool attached above which is the script you sent works though!) – for the same file in question
PS:
how do you zip javascript scripts to share? For some reason .js is an invalid file format to share on the forum... and WinRar is unable to zip a javascript file it seems...
I guess this website is an option...
https://www.ezyzip.com/convert-js-to-zip.html
thank you for the fix... I am decent with autohotkey, but JavaScript is something else... (but I like learning about it) Oh and thank you for adding headings in your scripts explaining what each part is for...
edit:
some ideas maybe I'll try and add it later
1) toggled (checkbox) to open the clean document in PDF-XCE (but not closing the original document tab)
2) toggles to remove only certain types of annotations and not all (all could be on by default and you could de-toggle the ones you want to keep
a) textboxes
b) shapes
c) stamps/images
d) highlights
Last edited by MedBooster on Tue Dec 10, 2024 11:54 am, edited 2 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
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
- Stefan - PDF-XChange
- Site Admin
- Posts: 19285
- Joined: Mon Jan 12, 2009 8:07 am
- Contact:
Re: Save without comments [Suggestion]
Hello MedBooster, Mathew,
Thank you both for this topic and glad to hear that all is now working correctly for @MedBooster.
Kind regards,
Stefan
Thank you both for this topic and glad to hear that all is now working correctly for @MedBooster.
Kind regards,
Stefan
-
- User
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Re: Save without comments [Suggestion]
Dear Mathew,
On a related JavaScript note
would you consider opening a new thread and paste in all your javscripts?
I think that would be a great opportunity for people like me to see what the expert himself uses (unless you have some sensitive information you don't want to share)
I don't mind presets / settings being set to your liking or changed from the default
1) it would save time having one zipped file as opposed to many...
2) seeing what you use yourself would be useful to understand what is maybe more depreciated (a few of the scripts are less useful with newer version of PDF-XCE with improvements.
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
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
- Stefan - PDF-XChange
- Site Admin
- Posts: 19285
- Joined: Mon Jan 12, 2009 8:07 am
- Contact:
Re: Save without comments [Suggestion]
Hello MedBooster,
While awaiting Mathew's feedback on your above request - you have yourself already done a very good job here:
viewtopic.php?t=42190
In collecting the scripts he has posted!
Kind regards,
Stefan
While awaiting Mathew's feedback on your above request - you have yourself already done a very good job here:
viewtopic.php?t=42190
In collecting the scripts he has posted!
Kind regards,
Stefan
Re: Save without comments [Suggestion]
Most of my scripts are in your forum post that Stefan linked to. I have a few more that I use regularly, but haven't got around to packaging up. None of them are obfuscated (or minified) so the commenting is still in there if you want to look at them. There are some snippets/templates that I reuse over and over - I'll put together a post with those when I get a chance.MedBooster wrote: ↑Tue Dec 10, 2024 3:35 pm On a related JavaScript note
would you consider opening a new thread and paste in all your javscripts?
I think that would be a great opportunity for people like me to see what the expert himself uses (unless you have some sensitive information you don't want to share)
I wouldn't call myself an "expert". If you look at the scripts, you can see that I've been learning as I go. Lots of searching on the web for information, help/hints from people Tracker, and trial & error. Because of the limitations of javascript within pdf applications, a lot of time is actually spent doing workarounds.
The most useful link is of course the javascript API [url]https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html[/url] I made a pdf copy and have added to it with PDFX-Change's improvements - I find a pdf easier to reference than a web site (•̅灬•̅ ) Probably not legal for me to share here though.
For zipping files, I use 7-zip [url]https://www.7-zip.org/[/url] which adds a context menu to explorer so I can right click and pick to compress. Once you have a zip, you can copy other files into it natively within explorer.
-
- User
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Re: Save without comments [Suggestion]
Well feel free to share a package/zipped file of your favourites if/when you have time
PS:
do you have a script which would copy over text from multiple selected comments (e.g. textboxes) ... or sticky notes etc... → to the clipboard?
Check out this thread for context
viewtopic.php?t=44623&hilit=copy+text+multiple
PS:
do you have a script which would copy over text from multiple selected comments (e.g. textboxes) ... or sticky notes etc... → to the clipboard?
Check out this thread for context
viewtopic.php?t=44623&hilit=copy+text+multiple
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
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
- Stefan - PDF-XChange
- Site Admin
- Posts: 19285
- Joined: Mon Jan 12, 2009 8:07 am
- Contact:
Re: Save without comments [Suggestion]
Hello MedBooster,
JS inside PDF files can't really add arbitrary content to the clipboard. So while you might be able to e.g. execute a Copy command with some limitations - you can't generate a string (what you need to do to copy only the contents of your annotations) and then force that into the clipboard - most likely due to security limitations.
Have you tried the summarize comments feature? You should be able to quickly get a page with the text you need and then be able to copy from that?
Kind regards,
Stefan
JS inside PDF files can't really add arbitrary content to the clipboard. So while you might be able to e.g. execute a Copy command with some limitations - you can't generate a string (what you need to do to copy only the contents of your annotations) and then force that into the clipboard - most likely due to security limitations.
Have you tried the summarize comments feature? You should be able to quickly get a page with the text you need and then be able to copy from that?
Kind regards,
Stefan
Re: Save without comments [Suggestion]
Hah, this topic has morphed. As I mentioned before, much of the effort with scripting pdf's involves figuring out a way around the limitations.
The only way to get some text into the clipboard I can think of is to present a dialog and let the user copy it. app.response() is good for that:
The script combines the text in the order the annotations were selected, I think.
The only way to get some text into the clipboard I can think of is to present a dialog and let the user copy it. app.response() is good for that:
Code: Select all
// get text from multiple comments
getTextMultipleAnnots( this );
function getTextMultipleAnnots( doc ) {
// get the selected comments
const selAnns = doc?.selectedAnnots;
if (!selAnns?.length) return; // nothing selected
// delimiter between the text of each annot
const delim = ' ';
// loop through them and add their contents
let allText = '';
for (const c of selAnns) {
let txt = c.contents;
if (txt) {
// maybe add a delimiter
allText += (allText ? delim : '') + txt;
}
}
// can't access the clipboard, so show a dialog to allow copying if there's something in allText
if (allText) {
app.response({
cQuestion: 'This is all the text from the selected comments:',
cTitle: 'Copy Text',
cDefault: allText,
cLabel: 'Copy:'});
}
}
Re: Save without comments [Suggestion]
The problem with using app.response is that it just cuts the text at the first newline. If there are newlines, then you'd need to make a custom dialog with an 'edit_text' box with 'multiline: true'. A bit more work:
Code: Select all
// get text from multiple comments
getTextMultipleAnnots( this);
function getTextMultipleAnnots( doc) {
// get the selected comments
const selAnns = doc?.selectedAnnots;
if (!selAnns?.length) return; // nothing selected
// delimiter between the text of each annot
const delim = '\n';
// loop through them and add their contents
let allText = '';
for (const c of selAnns) {
let txt = c.contents;
if (txt) {
// maybe add a delimiter
allText += (allText ? delim : '') + txt;
}
}
// can't access the clipboard, so show a dialog to allow copying if there's something in allText
const txtDialog = {
results: '',
initialize(dialog) {
dialog.load({cpTx: this.results});
},
commit (dialog) {
this.results = dialog.store().cpTx; // Retrieve dialog input values
},
description: {
name: "Copy Text",
width: 400,
elements:
[
{ type: 'static_text', name: 'This is all the text from the selected comments:' },
{ type: 'edit_text', item_id: 'cpTx', width: 400, char_height: 7, multiline: true },
{ type: 'ok'}
]
}
};
txtDialog.results = allText;
app.execDialog( txtDialog );
// also return the text
return allText;
}
-
- User
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Re: Save without comments [Suggestion]
Amaaazing maybe open a new thread for this with [JavaScript] in the title?
So what you've made here would be veeery useful.... as "summarize comments" doesn't allow for this.... Summarize comments also adds comment title information, while what we want here is just the text content.
viewtopic.php?t=44623TrackerSupp-Daniel wrote: ↑Wed Dec 11, 2024 7:14 pm 2) It is not currently possible to summarize only the selected comments. Summaries are for all comments on the defined pages, specifically.
Kind regards,
So what you've made here would be veeery useful.... as "summarize comments" doesn't allow for this.... Summarize comments also adds comment title information, while what we want here is just the text content.
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
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
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Re: Save without comments [Suggestion]
should function be changed to const?
I don't see if the "last line" should be changed in this case as well
I guess "true" is unnecessary in this case... but removing it did nothing... hmm
I tried making it work for a while...
It's just having it as a menu item would be super useful to me
Also,
how would you attach a keyboard shortcut to it? the Windows key can not be used as a modifier key in JavaScript PDF-XCE, right?
I don't see if the "last line" should be changed in this case as well
I guess "true" is unnecessary in this case... but removing it did nothing... hmm
I tried making it work for a while...
It's just having it as a menu item would be super useful to me
Also,
how would you attach a keyboard shortcut to it? the Windows key can not be used as a modifier key in JavaScript PDF-XCE, right?
Code: Select all
// Add tool button for getting text from multiple comments
app.addToolButton({
cName: "GetTextFromMultipleComments",
cLabel: "Get TMC",
cTooltext: "Open a dialog to get text from selected annotations.",
cExec: "getTextMultipleAnnots( this, true);" // Pass the active document
});
// get text from multiple comments
getTextMultipleAnnots( this);
function getTextMultipleAnnots( doc) {
// get the selected comments
const selAnns = doc?.selectedAnnots;
if (!selAnns?.length) return; // nothing selected
// delimiter between the text of each annot
const delim = '\n';
// loop through them and add their contents
let allText = '';
for (const c of selAnns) {
let txt = c.contents;
if (txt) {
// maybe add a delimiter
allText += (allText ? delim : '') + txt;
}
}
// can't access the clipboard, so show a dialog to allow copying if there's something in allText
const txtDialog = {
results: '',
initialize(dialog) {
dialog.load({cpTx: this.results});
},
commit (dialog) {
this.results = dialog.store().cpTx; // Retrieve dialog input values
},
description: {
name: "Copy Text",
width: 400,
elements:
[
{ type: 'static_text', name: 'This is all the text from the selected comments:' },
{ type: 'edit_text', item_id: 'cpTx', width: 400, char_height: 7, multiline: true },
{ type: 'ok'}
]
}
};
txtDialog.results = allText;
app.execDialog( txtDialog );
// also return the text
return allText;
}
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
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
Re: Save without comments [Suggestion]
... we're fiddling on this at the same time. I just posted a script that adds a toolbar item, and also gets the rich contents in markups. That added yet another issue, because I don't think you can have rich contents in dialog boxes, so I made a new document and put the results into a text field.
viewtopic.php?p=187876#p187876
viewtopic.php?p=187876#p187876
Last edited by Mathew on Wed Dec 11, 2024 9:06 pm, edited 1 time in total.
Re: Save without comments [Suggestion]
Sorry in that one I'd put the function call at the beginning -- I thought I was making it easier! See my post on your other topic.MedBooster wrote: ↑Wed Dec 11, 2024 7:46 pm should function be changed to const?
I don't see if the "last line" should be changed in this case as well
I guess "true" is unnecessary in this case... but removing it did nothing... hmm
I tried making it work for a while...
It's just having it as a menu item would be super useful to me
Also,
how would you attach a keyboard shortcut to it? the Windows key can not be used as a modifier key in JavaScript PDF-XCE, right?
Correct, the function has no second parameter.
Keyboard shortcut: You can assign a keyboard shortcut to scripts that are added as addMenuItem -- but the shortcuts only last as long as the application is running. I think it's on the active development todo list though, so maybe we'll have something in the future.
Re: Save without comments [Suggestion]
I made a version with a menu item and icon.
Unzip and save in the Javascripts folder (which can be either in the application folder or in %APPDATA%\Tracker Software\PDFXEditor\3.0\ ) It adds to the quick access bar on the ribbon UI and the file menu on the classic UI: (screen capture by @medbooster)
This version makes a copy of the file adding [clean] to the end of the file name, then opens it and deletes all the annotations in that copy. There will be a security warning when the script tries to open the copy.
Unzip and save in the Javascripts folder (which can be either in the application folder or in %APPDATA%\Tracker Software\PDFXEditor\3.0\ ) It adds to the quick access bar on the ribbon UI and the file menu on the classic UI: (screen capture by @medbooster)
This version makes a copy of the file adding [clean] to the end of the file name, then opens it and deletes all the annotations in that copy. There will be a security warning when the script tries to open the copy.
Last edited by Mathew on Mon Jan 13, 2025 6:18 pm, edited 1 time in total.
-
- User
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Re: Save without comments [Suggestion]
As always, amazing work!
If you're up for a new challenge... About saving all tabs in a window to the same location (not having to save each tab manually)
– meaning that it only would ask where to save the 1st document in the tab – and the rest would follow...
viewtopic.php?t=44841
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
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
- Dimitar - PDF-XChange
- Site Admin
- Posts: 2147
- Joined: Mon Jan 15, 2018 9:01 am
-
- User
- Posts: 1349
- Joined: Mon Nov 15, 2021 8:38 pm
Re: Save without comments [Suggestion]
without markup
Is this related, I am confused?
This seems new, can't find it in the command menu
Is this related, I am confused?
This seems new, can't find it in the command menu
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
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
Re: Save without comments [Suggestion]
Yes, that's the tool icon (posted above)! I didn't get around to making a detailed post about it viewtopic.php?p=187923#p187923
[edit]
[edit]
I took your screen capture and added it to the post.
Last edited by Mathew on Mon Jan 13, 2025 6:20 pm, edited 1 time in total.
- Dimitar - PDF-XChange
- Site Admin
- Posts: 2147
- Joined: Mon Jan 15, 2018 9:01 am