Set password for output document

View as Markdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Comparison MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

On this page

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

To protect 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 password:

import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.CompareOptions;
import com.groupdocs.comparison.options.enums.PasswordSaveOption;
import com.groupdocs.comparison.options.save.SaveOptions;
import java.nio.file.Path;
// ...


try (Comparer comparer = new Comparer("source.docx")) {
    comparer.add("target.docx");

    CompareOptions compareOptions = new CompareOptions();
    compareOptions.setPasswordSaveOption(PasswordSaveOption.USER);
    SaveOptions saveOptions = new SaveOptions();
    saveOptions.setPassword("3333");
    final Path resultPath = comparer.compare("result.docx", saveOptions, compareOptions);
}

On this page

Close

Ask anything about this page — the answer is based on its content.

Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.