Load Options
Leave feedback
On this page
Use groupdocs.parser.options.LoadOptions to pass extra parameters when opening a document, such as a password or file type when loading from a stream.
from groupdocs.parser import Parser
from groupdocs.parser.options import LoadOptions
options = LoadOptions("secret-password")
with Parser("protected.pdf", options) as parser:
reader = parser.get_text()
print(reader if reader else "Text extraction isn't supported.")
The following sample file is used in this example: protected.pdf
When you read from a stream, provide LoadOptions so the parser knows how to open the content (for example, password-protected PDF streams).
from groupdocs.parser import Parser
from groupdocs.parser.options import LoadOptions
with open("resources/protected.pdf", "rb") as stream:
options = LoadOptions("secret-password")
with Parser(stream, options) as parser:
reader = parser.get_text()
print(reader if reader else "Text extraction isn't supported.")
The following sample file is used in this example: protected.pdf
- Always dispose of streams and parsers with
withstatements. - If a password is wrong, the parser raises an exception (see errors and exceptions).
- For additional options (e.g., file type hints), see the
LoadOptionsAPI reference.
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.