Parser Constructor (Stream, LoadOptions) |
Namespace: GroupDocs.Parser
In some cases it's necessary to define FileFormat. Both for special cases (databases, email server) and for detecting file types by the content:
// 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:
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"); }