The following example shows how to extract data from Sqlite database:
// Create DbConnection objectDbConnectionconnection=newSQLiteConnection(string.Format("Data Source={0};Version=3;",Constants.SampleDatabase));// Create an instance of Parser class to extract tables from the databaseusing(Parserparser=newParser(connection)){// Check if text extraction is supportedif(!parser.Features.Text){Console.WriteLine("Text extraction isn't supported.");return;}// Check if toc extraction is supportedif(!parser.Features.Toc){Console.WriteLine("Toc extraction isn't supported.");return;}// Get a list of tablesIEnumerable<TocItem>toc=parser.GetToc();// Iterate over tablesforeach(TocItemiintoc){// Print the table nameConsole.WriteLine(i.Text);// Extract a table content as a textusing(TextReaderreader=parser.GetText(i.PageIndex.Value)){Console.WriteLine(reader.ReadToEnd());}}}
The following example shows how to extract data from Sqlite database:
// Create DbConnection objectDbConnectionconnection=newSQLiteConnection(string.Format("Data Source={0};Version=3;",Constants.SampleDatabase));// Create an instance of Parser class to extract tables from the databaseusing(Parserparser=newParser(connection)){// Check if text extraction is supportedif(!parser.Features.Text){Console.WriteLine("Text extraction isn't supported.");return;}// Check if toc extraction is supportedif(!parser.Features.Toc){Console.WriteLine("Toc extraction isn't supported.");return;}// Get a list of tablesIEnumerable<TocItem>toc=parser.GetToc();// Iterate over tablesforeach(TocItemiintoc){// Print the table nameConsole.WriteLine(i.Text);// Extract a table content as a textusing(TextReaderreader=parser.GetText(i.PageIndex.Value)){Console.WriteLine(reader.ReadToEnd());}}}
The following example shows how to extract emails from Exchange Server:
// Create the connection object for Exchange Web Services protocol EmailConnectionconnection=newEmailEwsConnection("https://outlook.office365.com/ews/exchange.asmx","email@server","password");// Create an instance of Parser class to extract emails from the remote serverusing(Parserparser=newParser(connection)){// Check if container extraction is supportedif(!parser.Features.Container){Console.WriteLine("Container extraction isn't supported.");return;}// Extract email messages from the serverIEnumerable<ContainerItem>emails=parser.GetContainer();// Iterate over attachmentsforeach(ContainerItemiteminemails){// Create an instance of Parser class for email messageusing(ParseremailParser=item.OpenParser()){// Extract the email textusing(TextReaderreader=emailParser.GetText()){// Print the email textConsole.WriteLine(reader==null?"Text extraction isn't supported.":reader.ReadToEnd());}}}}
The following example shows how to extract emails from Exchange Server:
// Create the connection object for Exchange Web Services protocol EmailConnectionconnection=newEmailEwsConnection("https://outlook.office365.com/ews/exchange.asmx","email@server","password");// Create an instance of Parser class to extract emails from the remote serverusing(Parserparser=newParser(connection)){// Check if container extraction is supportedif(!parser.Features.Container){Console.WriteLine("Container extraction isn't supported.");return;}// Extract email messages from the serverIEnumerable<ContainerItem>emails=parser.GetContainer();// Iterate over attachmentsforeach(ContainerItemiteminemails){// Create an instance of Parser class for email messageusing(ParseremailParser=item.OpenParser()){// Extract the email textusing(TextReaderreader=emailParser.GetText()){// Print the email textConsole.WriteLine(reader==null?"Text extraction isn't supported.":reader.ReadToEnd());}}}}
The following example shows how to load the document from the local disk:
// Create an instance of Parser class with the filePathusing(Parserparser=newParser(filePath)){// Extract a text into the readerusing(TextReaderreader=parser.GetText()){// Print a text from the document// If text extraction isn't supported, a reader is nullConsole.WriteLine(reader==null?"Text extraction isn't supported":reader.ReadToEnd());}}
The document password is passed by LoadOptions class:
try{// Create an instance of Parser class with the password:using(Parserparser=newParser(filePath,newLoadOptions(password))){// Check if text extraction is supportedif(!parser.Features.Text){Console.WriteLine("Text extraction isn't supported.");return;}// Print the document textusing(TextReaderreader=parser.GetText()){Console.WriteLine(reader.ReadToEnd());}}}catch(InvalidPasswordException){// Print the message if the password is incorrect or emptyConsole.WriteLine("Invalid password");}
The following example shows how to receive the information via ILogger interface:
// try{// Create an instance of Logger classLoggerlogger=newLogger();// Create an instance of Parser class with the parser settingsusing(Parserparser=newParser(filePath,null,newParserSettings(logger))){// Check if text extraction is supportedif(!parser.Features.Text){Console.WriteLine("Text extraction isn't supported.");return;}// Print the document textusing(TextReaderreader=parser.GetText()){Console.WriteLine(reader.ReadToEnd());}}}catch(InvalidPasswordException){;// Ignore the exception}privateclassLogger:ILogger{publicvoidError(stringmessage,Exceptionexception){// Print error messageConsole.WriteLine("Error: "+message);}publicvoidTrace(stringmessage){// Print event messageConsole.WriteLine("Event: "+message);}publicvoidWarning(stringmessage){// Print warning messageConsole.WriteLine("Warning: "+message);}}
The following example shows how to load the document from the stream:
// Create an instance of Parser class with the streamusing(Parserparser=newParser(stream)){// Extract a text into the readerusing(TextReaderreader=parser.GetText()){// Print a text from the document// If text extraction isn't supported, a reader is nullConsole.WriteLine(reader==null?"Text extraction isn't supported":reader.ReadToEnd());}}
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 documentusing(Parserparser=newParser(stream,newLoadOptions(FileFormat.Markup))){// Check if text extraction is supportedif(!parser.Features.Text){Console.WriteLine("Text extraction isn't supported.");return;}using(TextReaderreader=parser.GetText()){// Print the document text// Markdown is detected; text without special symbols is printedConsole.WriteLine(reader.ReadToEnd());}}
The document password is passed by LoadOptions class:
try{// Create an instance of Parser class with the password:using(Parserparser=newParser(filePath,newLoadOptions(password))){// Check if text extraction is supportedif(!parser.Features.Text){Console.WriteLine("Text extraction isn't supported.");return;}// Print the document textusing(TextReaderreader=parser.GetText()){Console.WriteLine(reader.ReadToEnd());}}}catch(InvalidPasswordException){// Print the message if the password is incorrect or emptyConsole.WriteLine("Invalid password");}
The following example shows how to receive the information via ILogger interface:
// try{// Create an instance of Logger classLoggerlogger=newLogger();// Create an instance of Parser class with the parser settingsusing(Parserparser=newParser(stream,null,newParserSettings(logger))){// Check if text extraction is supportedif(!parser.Features.Text){Console.WriteLine("Text extraction isn't supported.");return;}// Print the document textusing(TextReaderreader=parser.GetText()){Console.WriteLine(reader.ReadToEnd());}}}catch(InvalidPasswordException){;// Ignore the exception}privateclassLogger:ILogger{publicvoidError(stringmessage,Exceptionexception){// Print error messageConsole.WriteLine("Error: "+message);}publicvoidTrace(stringmessage){// Print event messageConsole.WriteLine("Event: "+message);}publicvoidWarning(stringmessage){// Print warning messageConsole.WriteLine("Warning: "+message);}}