To open a password-protected document, create a LoadOptions instance with the file format and set the password property.
fromgroupdocs.markdownimportMarkdownConverter,LoadOptions,FileFormatdefload_password_static():"""Open a password-protected document and convert using the static API."""# Step 1: Create load options with format and passwordload_options=LoadOptions(FileFormat.DOCX)load_options.password="secret"# Step 2: Convert the protected document using keyword argumentMarkdownConverter.to_file("protected.docx","load-password-static.md",load_options=load_options)if__name__=="__main__":load_password_static()
protected.docx is sample file used in this example. Click here to download it.
# **Title of the document**
## **Subtitle #1**
Text is normal, then **bold**, then *italic*, then underscore, and finally normal again. Now ~~strikethrough~~, then double strikethrough, and underscore differently - with dashes. Another underscore is marked with yellow wave line. And then – underscore and strikethrough ~~together~~! Here we have a superscript123 and a subscript456. This part of text has a red background. These words are shadowed to right side, these – shadowed (red) to top sid
...
# **Title of the document**
## **Subtitle #1**
Text is normal, then **bold**, then *italic*, then underscore, and finally normal again. Now ~~strikethrough~~, then double strikethrough, and underscore differently - with dashes. Another underscore is marked with yellow wave line. And then – underscore and strikethrough ~~together~~! Here we have a superscript123 and a subscript456. This part of text has a red background. These words are shadowed to right side, these – shadowed (red) to top sid
[TRUNCATED]
fromgroupdocs.markdownimportMarkdownConverter,LoadOptions,FileFormatdefload_password_instance():"""Open a password-protected spreadsheet and convert using the instance API."""# Step 1: Create load options with format and passwordload_options=LoadOptions(FileFormat.XLSX)load_options.password="secret"# Step 2: Open the protected document using keyword argument for load optionswithMarkdownConverter("protected.xlsx",load_options=load_options)asconverter:# Step 3: Convert and save the Markdown outputconverter.convert("load-password-instance.md")if__name__=="__main__":load_password_instance()
protected.xlsx is sample file used in this example. Click here to download it.
If the password is missing or incorrect, a DocumentProtectedException is raised. You can catch it to display a user-friendly message:
fromgroupdocs.markdownimportMarkdownConverter,DocumentProtectedExceptiondefload_password_exception():"""Handle incorrect or missing passwords when opening protected documents."""try:# Step 1: Attempt to convert without providing a passwordmarkdown=MarkdownConverter.to_markdown("protected.docx")exceptDocumentProtectedExceptionasex:# Step 2: Catch the exception and display a user-friendly messageprint(f"Cannot open document: {ex}")if__name__=="__main__":load_password_exception()
protected.docx is sample file used in this example. Click here to download it.
Cannot open document: The document password is incorrect.
[.NET GroupDocs.Markdown.DocumentProtectedException]
at .(Stream , LoadOptions )
at .(Stream , LoadOptions , ConvertOptions , Stream )
at GroupDocs.Markdown.MarkdownConverter.(ConvertOptions , Stream , Boolean )
at GroupDocs.Markdown.MarkdownConverter.Convert(ConvertOptions convertOptions)
at GroupDocs.Markdown.MarkdownConverter.ToMarkdown(String sourcePath, LoadOptions loadOptions, ConvertOptions
...