Load password-protected document

View as MarkdownMarkdown

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.Conversion 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-conversion -- dnx GroupDocs.Conversion.Mcp --yes
Folders, licensing and more →

GroupDocs.Conversion supports the conversion of documents that are protected with a password.

To load and convert a password-protected document, follow these steps:

  1. Create an instance of the Converter class and pass the source document path and the load options delegate as constructor parameters.
  2. Instantiate the appropriate ConvertOptions class e.g. (PdfConvertOptions, WordProcessingConvertOptions, SpreadsheetConvertOptions, etc.)
  3. Call the convert method of the Converter class instance and pass the filename for the converted document and the instance of ConvertOptions from the previous step.

The following code snippet shows how to convert password-protected document:

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.WordProcessingLoadOptions;

public class LoadPasswordProtectedFile {
    public static void loadPasswordProtectedFile() {
        // Set file path
        String filePath = "./password-protected.docx";

        // Instantiate load options and set password
        WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
        loadOptions.setPassword("12345");

        // Specify source file path and load options
        Converter converter = new Converter(filePath, () -> loadOptions);

        // Specify output file location and convert options
        String outputPath = "./password-protected.pdf";
        PdfConvertOptions convertOptions = new PdfConvertOptions();
        convertOptions.setPassword("67890");

        // Convert and save to output path
        converter.convert(outputPath, convertOptions);
    }

    public static void main(String[] args){
        loadPasswordProtectedFile();
    }
}

password-protected.docx is sample file used in this example. Click here to download it.

password-protected.pdf is converted PDF document. Click here to download it. The file is password-protected. Password is 67890.