The following code snippet shows how to compare two documents and protect the output document with a user password.
'use strict';// Import the GroupDocs.Comparison for Node.js via Java SDK
constgroupdocs=require('@groupdocs/groupdocs.comparison');// Define file paths for the source, target, and password-protected result
constsourceFile='sample-files/source.docx';consttargetFile='sample-files/target.docx';constoutputFile='result.docx';// Initialize the comparer with the source document
constcomparer=newgroupdocs.Comparer(sourceFile);// Add the target document to the comparison session
comparer.add(targetFile);// Configure comparison options to indicate that a user password will be set
constcompareOptions=newgroupdocs.CompareOptions();compareOptions.setPasswordSaveOption(groupdocs.PasswordSaveOption.USER);// Configure save options with the desired document password
constsaveOptions=newgroupdocs.SaveOptions();saveOptions.setPassword('3333');// password that will be required to open the result
// Run the comparison, applying both save and comparison options
comparer.compare(outputFile,saveOptions,compareOptions);// Terminate the process with a success exit code
process.exit(0);
This example creates a Comparer instance with the source document, adds the target document, and creates both CompareOptions and SaveOptions objects. It sets setPasswordSaveOption(PasswordSaveOption.USER) in the CompareOptions to indicate that a user password will be applied, and sets the actual password using setPassword('3333') in the SaveOptions. When the comparison is performed with both options, the result document will be password-protected and require the specified password to open.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.