Set password for output document

On this page

GroupDocs.Comparison allows you to protect the output document with a password.

To protect the output document, follow these steps:

  1. Instantiate the Comparer object. Specify the source document path or stream.
  2. Call the add() method. Specify the target document path or stream.
  3. Instantiate the CompareOptions object. Call the setPasswordSaveOption() method and specify the PasswordSaveOption.USER value.
  4. Instantiate the SaveOptions object. Call the setPassword() property to specify a password string.
  5. Call the compare() method. Specify the SaveOptions and CompareOptions objects as parameters.

The following code snippet shows how to compare documents and protect the output document with a password:


const comparer = new groupdocs.comparison.Comparer(sourceFile);
comparer.add(targetFile);

const compareOptions = new groupdocs.comparison.CompareOptions();
compareOptions.setPasswordSaveOption(groupdocs.comparison.PasswordSaveOption.USER);
SaveOptions saveOptions = new groupdocs.comparison.SaveOptions();
saveOptions.setPassword("3333");
const resultPath = comparer.compare(outputFile, saveOptions, compareOptions);

On this page