Extract text from Microsoft OneNote sections

To extract a text from Microsoft OneNote Sections GetText and GetText(pageIndex) methods are used. These methods allow to extract a text from the entire document or a text from the selected page. Raw mode is not supported for Microsoft OneNote.

Here are the steps to extract a text from Microsoft OneNote Section:

  • Instantiate Parser object for the initial section;
  • Call GetText method and obtain TextReader object;
  • Read a text from reader.
Warning
GetText method returns null value if text extraction isn’t supported for the document. For example, text extraction isn’t supported for Zip archive. Therefore, for Zip archive GetText method returns null. For empty Microsoft OneNote Section GetText method returns an empty TextReader object (reader.ReadToEnd method returns an empty string).

The following example demonstrates how to extract a text from Microsoft OneNote Section:

// Create an instance of Parser class
using(Parser parser = new Parser(filePath))
{
    // Extract a text into the reader
    using(TextReader reader = parser.GetText())
    {
        // Print a text from the section
        Console.WriteLine(reader.ReadToEnd());
    }
}

Here are the steps to extract a text from the page of Microsoft OneNote Section:

The following example demonstrates how to extract a text from the page of Microsoft OneNote Section:

// Create an instance of Parser class
using(Parser parser = new Parser(filePath))
{
    // Get the document info
    IDocumentInfo documentInfo = parser.GetDocumentInfo();
   
    // Iterate over pages
    for(int p = 0; p < documentInfo.PageCount; p++)
    {
        // Print a page number 
        Console.WriteLine(string.Format("Page {0}/{1}", p + 1, documentInfo.PageCount));
   
        // Extract a text into the reader
        using(TextReader reader = parser.GetText(p))
        {
            // Print a text from the section
            Console.WriteLine(reader.ReadToEnd());
        }
    }
}

More resources

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document parser App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to parse documents and extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Parser App.