Load password-protected documents
Leave feedback
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:
- Instantiate the HtmlViewOptions (or PngViewOptions, or JpgViewOptions, or PdfViewOptions) object.
- Set a password using the LoadOptions.setPassword() method.NoteIf the password is not specified, GroupDocs.Viewer throws PasswordRequiredException. If the incorrect password is specified, GroupDocs.Viewer throws IncorrectPasswordException.
- Call the View.view() method.
The following code snippet shows how to load and render an encrypted document:
import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.HtmlViewOptions;
import com.groupdocs.viewer.options.LoadOptions;
// ...
LoadOptions loadOptions = new LoadOptions();
// Specify a password.
loadOptions.setPassword("123456");
// Render the file.
try (Viewer viewer = new Viewer("sample.docx", loadOptions)) {
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewer.view(viewOptions);
}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.