Parser Constructor (Stream, LoadOptions)
Initializes a new instance of the Parser class with LoadOptions.

Namespace: GroupDocs.Parser
Assembly: GroupDocs.Parser (in GroupDocs.Parser.dll) Version: 20.10.0
Syntax
public Parser(
	Stream document,
	LoadOptions loadOptions
)

Parameters

document
Type: System.IOStream
The source input stream.
loadOptions
Type: GroupDocs.Parser.OptionsLoadOptions
The options to open the file.
Remarks
Examples

In some cases it's necessary to define FileFormat. Both for special cases (databases, email server) and for detecting file types by the content:

C#
// Create an instance of Parser class for markdown document
using (Parser parser = new Parser(stream, new LoadOptions(FileFormat.Markup)))
{
    // Check if text extraction is supported
    if (!parser.Features.Text)
    {
        Console.WriteLine("Text extraction isn't supported.");
        return;
    }
    using (TextReader reader = parser.GetText())
    {
        // Print the document text
        // Markdown is detected; text without special symbols is printed
        Console.WriteLine(reader.ReadToEnd());
    }
}

The document password is passed by LoadOptions class:

C#
try
{
    // Create an instance of Parser class with the password:
    using (Parser parser = new Parser(filePath, new LoadOptions(password)))
    {
        // Check if text extraction is supported
        if (!parser.Features.Text)
        {
            Console.WriteLine("Text extraction isn't supported.");
            return;
        }
        // Print the document text
        using (TextReader reader = parser.GetText())
        {
            Console.WriteLine(reader.ReadToEnd());
        }
    }
}
catch (InvalidPasswordException)
{
    // Print the message if the password is incorrect or empty
    Console.WriteLine("Invalid password");
}
See Also