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("123456")

with Parser("protected.pdf", options) as parser:
    reader = parser.get_text()
    text = reader.read_to_end() if reader is not None else None
    print(text if text is not None 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("protected.pdf", "rb") as stream:
    options = LoadOptions("123456")
    with Parser(stream, options) as parser:
        reader = parser.get_text()
        text = reader.read_to_end() if reader is not None else None
        print(text if text is not None else "Text extraction isn't supported.")

The following sample file is used in this example: protected.pdf

Tips

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.