Load password-protected documents

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

The encryption protects data and allows only authorized people to open the file. When a file is encrypted, the password must be specified to open the file. To learn how to identify the encrypted file, please refer to the Check if a file is encrypted page.

To load and render an encrypted document, follow these steps:

  1. Instantiate the HtmlViewOptions (or PngViewOptions, or JpgViewOptions, or PdfViewOptions) object.
  2. Set a password in the LoadOptions.Password property.
    Note
    If the password is not specified, GroupDocs.Viewer throws PasswordRequiredException.
  3. Call the View method.

The following code snippet shows how to load and render an encrypted document:

using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
// ...

// Specify a password.
LoadOptions loadOptions = new LoadOptions();
loadOptions.Password = "123456";
// Render a file.
using (Viewer viewer = new Viewer("encrypted.docx", loadOptions))
{
    HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
    viewer.View(viewOptions);
}
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
' ...

Module Program
    Sub Main(args As String())
        ' Specify a password.
        Dim loadOptions As LoadOptions = New LoadOptions()
        loadOptions.Password = "123456"
        ' Render a file.
        Using viewer As Viewer = New Viewer("encrypted.docx", loadOptions)
            Dim viewOptions As HtmlViewOptions = HtmlViewOptions.ForEmbeddedResources()
            viewer.View(viewOptions)
        End Using
    End Sub
End Module

encrypted.docx is the sample file used in this example. Click here to download it.

p_1.html (117 KB)
p_2.html (90 KB)

Download full output