Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/c472c90dc92b80a384e516e1064d722b to your computer and use it in GitHub Desktop.
Save aspose-com-gists/c472c90dc92b80a384e516e1064d722b to your computer and use it in GitHub Desktop.
Extract Text and Images from OneNote Documents using C#

Learn how to extract text and images from OneNote documents using C#.

The following topics are covered in this article:

  1. OneNote Text and Image Extractor C# API
  2. Extract All the Text from OneNote Documents
  3. Get Text from Specific Pages of OneNote Documents
  4. Extract Images from OneNote Documents
// This code example demonstrates how to extract all the text from OneNote document.
// Load the document into Aspose.Note.
Document oneFile = new Document(@"C:\Files\Note\Aspose.one");
// Retrieve text
string text = string.Join(Environment.NewLine, oneFile.GetChildNodes<RichText>().Select(e => e.Text)) + Environment.NewLine;
// Print text
Console.WriteLine(text);
// This code example demonstrates how to get text from a specific page.
// Get First page from list of page nodes
var page = oneFile.GetChildNodes<Page>().FirstOrDefault();
if (page != null)
{
// Retrieve text
IList<RichText> textNodes = page.GetChildNodes<RichText>();
foreach (RichText t in textNodes)
{
// Print text
Console.WriteLine(t.Text);
}
}
// This code example demonstrates how to extract all the images.
// Get all Image nodes
IList<Aspose.Note.Image> nodes = oneFile.GetChildNodes<Aspose.Note.Image>();
foreach (Aspose.Note.Image image in nodes)
{
Console.WriteLine("Width: {0}", image.Width);
Console.WriteLine("Height: {0}", image.Height);
Console.WriteLine("OriginalWidth: {0}", image.OriginalWidth);
Console.WriteLine("OriginalHeight: {0}", image.OriginalHeight);
Console.WriteLine("FileName: {0}", image.FileName);
Console.WriteLine("LastModifiedTime: {0}", image.LastModifiedTime);
using (MemoryStream stream = new MemoryStream(image.Bytes))
{
using (Bitmap bitMap = new Bitmap(stream))
{
// Save image bytes to a file
bitMap.Save(String.Format(@"C:\Files\Note\" + "{0}", Path.GetFileName(image.FileName)));
}
}
Console.WriteLine("Image saved!");
Console.WriteLine();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment