Load a password-protected document

To open a password-protected document, create a LoadOptions instance with the file format and call setPassword.

import com.groupdocs.markdown.*;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

public class LoadPasswordStatic {

    public static void main(String[] args) throws IOException {
        LoadOptions loadOptions = new LoadOptions(FileFormat.DOCX);
        loadOptions.setPassword("secret");

        // Static one-liner
        String markdown = MarkdownConverter.toMarkdown("protected.docx", loadOptions);
        Files.write(Paths.get("load-password-static.md"), markdown.getBytes(StandardCharsets.UTF_8));
    }
}

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

**Confidential Memo**

From: Meridian Outdoor Co. — Strategy Team

Date: 2026-01-15

Subject: FY2026 M&A Targets



[TRUNCATED]

Download full output

Using instance API

Warning
Password-protected spreadsheets do not open in 26.5. The example below is correct, but the library rejects a valid password on an encrypted XLSX with Invalid password. — the same file and password open normally in GroupDocs.Markdown for .NET. Password-protected Word documents (above) work. This is being tracked as a library defect; no verified output is published for this example until it is fixed.
import com.groupdocs.markdown.*;

public class LoadPasswordInstance {

    public static void main(String[] args) {
        LoadOptions loadOptions = new LoadOptions(FileFormat.XLSX);
        loadOptions.setPassword("secret");

        try (MarkdownConverter converter = new MarkdownConverter("protected.xlsx", loadOptions)) {
            converter.convert("load-password-instance.md");
        }
    }
}

protected.xlsx is a sample file used in this example. Click here to download it.

Handling incorrect passwords

If the password is missing or incorrect the conversion fails. Catch GroupDocsMarkdownException to display a user-friendly message — see Error handling for why the base type rather than DocumentProtectedException:

import com.groupdocs.markdown.*;

public class LoadPasswordException {

    public static void main(String[] args) {
        try {
            String markdown = MarkdownConverter.toMarkdown("protected.docx");
        } catch (GroupDocsMarkdownException e) {
            System.out.println("Cannot open document: " + e.getMessage());
        }
    }
}

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

Cannot open document: com.groupdocs.markdown.DocumentProtectedException: The document password is incorrect.

Download full output

Close
Loading

Analyzing your prompt, please hold on...

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