Compare multiple documents protected by password
Leave feedback
On this page
Note
This feature is available only for Word documents, PowerPoint, and Open Document presentations.
GroupDocs.Comparison allows you to compare more than two password-protected documents.
The following code snippets show how to compare several password-protected documents:
Compare several password-protected documents from a local disk
The following example compares a password-protected source document with three password-protected target documents from disk and saves a combined result.
'use strict';// Import the GroupDocs.Comparison for Node.js via Java SDK
constgroupdocs=require('@groupdocs/groupdocs.comparison');// Define file paths for the source document, three target documents, and the output result
constsourceFile='sample-files/source_protected.docx';consttargetFile1='sample-files/target_protected.docx';consttargetFile2='sample-files/target2_protected.docx';consttargetFile3='sample-files/target3_protected.docx';constresultFile='result.docx';// Create a Comparer instance for the source file, providing its password via LoadOptions
constcomparer=newgroupdocs.Comparer(sourceFile,newgroupdocs.LoadOptions('1234'));// Add the target documents with their passwords
comparer.add(targetFile1,newgroupdocs.LoadOptions('5678'));comparer.add(targetFile2,newgroupdocs.LoadOptions('5678'));comparer.add(targetFile3,newgroupdocs.LoadOptions('5678'));// Perform the comparison and save the merged result to the specified output file
comparer.compare(resultFile);// Terminate the process with a success exit code
process.exit(0);
This disk-based example:
Creates a Comparer instance for the password-protected source document using LoadOptions.
Adds each protected target document with its corresponding LoadOptions (containing the password) via add().
Calls compare() to generate a single result that merges changes across all password-protected documents.
Compare several password-protected documents from a stream
The following example performs the same operation using Java input streams instead of file paths.
'use strict';// Import the GroupDocs.Comparison for Node.js via Java SDK
constgroupdocs=require('@groupdocs/groupdocs.comparison');// Import Java bridge and FileInputStream class
constjava=require('java');constInputStream=java.import('java.io.FileInputStream');// Define file paths for the protected documents and the result
constsourcePath='sample-files/source_protected.docx';consttargetPath1='sample-files/target_protected.docx';consttargetPath2='sample-files/target2_protected.docx';consttargetPath3='sample-files/target3_protected.docx';constresultPath='result_multiple_protected.docx';// Create input streams for source and targets
constsourceStream=newInputStream(sourcePath);consttargetStream1=newInputStream(targetPath1);consttargetStream2=newInputStream(targetPath2);consttargetStream3=newInputStream(targetPath3);// Initialize comparer for the protected source document
constcomparer=newgroupdocs.Comparer(sourceStream,newgroupdocs.LoadOptions('1234'));// Add protected target documents using their passwords
comparer.add(targetStream1,newgroupdocs.LoadOptions('5678'));comparer.add(targetStream2,newgroupdocs.LoadOptions('5678'));comparer.add(targetStream3,newgroupdocs.LoadOptions('5678'));// Compare all documents and save the combined result
comparer.compare(resultPath);// Terminate the process with a success exit code
process.exit(0);
In the stream-based scenario:
Input streams are opened for the source and each protected target document.
The Comparer is initialized with the source stream and its password through LoadOptions.
Target streams are added with their own LoadOptions instances that specify passwords.
The compare() method runs the multi-document comparison and outputs the merged result file.
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.