Load Options

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.

Open a password-protected document

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

Load from a stream

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

Tips