Add Image to OneNote in C#

OneNote allows collecting, organizing, and collaborating free-form information and multi-user collaboration in the form of notes, drawings, screen clippings, and audio commentaries. We can insert images into OneNote documents programmatically. In this article, we will learn how to add an image to a OneNote in C#.

The following topics shall be covered in this article:

  1. C# API to Add Images to OneNote
  2. Add Image to a New OneNote Document
  3. Insert Image into an Existing OneNote Document
  4. Add Image with Alternative Text

C# API to Add Images to OneNote

To add an image to a new or existing OneNote document, we will be using the Aspose.Note for .NET API. The API allows creating, reading, and converting OneNote documents programmatically without using Microsoft OneNote. It also allows importing content from PDF documents into OneNote documents.

Please either download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.Note

Add Image to New OneNote Document in C#

We can create a new OneNote document and insert an image by following the steps given below:

  1. Firstly, create an instance of the Document class.
  2. Next, initialize the Page class object.
  3. Then, load an image using the Image class.
  4. Optionally, set image height, width, alignment, offset, etc.
  5. After that, add the Image to the Page using the AppendChildLast() method.
  6. Similarly, add the Page to the Document.
  7. Finally, call the Save() method to save the OneNote document.

The following code sample shows how to add an image to a new OneNote document using C#.

Add-Image-to-New-OneNote-Document-in-CSharp

Add an Image to New OneNote Document in C#.

Add Image to Existing OneNote Document in C#

We can also insert an image into an existing OneNote document by following the steps given below:

  1. Firstly, load an existing OneNote using the Document class.
  2. Next, initialize the Page class object.
  3. Then, load an image using the Image class.
  4. Optionally, set image height, width, alignment, offset, etc.
  5. After that, add the Image to the Page using the AppendChildLast() method.
  6. Similarly, add the Page to the Document.
  7. Finally, call the Save() method to save the OneNote document.

The following code sample shows how to add an image to an existing OneNote document using C#.

Insert Image with Alternative Text in OneNote using C#

We can add image alternative text while inserting it into a OneNote document by following the steps given below:

  1. Firstly, create an instance of the Document class.
  2. Next, initialize the Page class object.
  3. Then, load an image using the Image class.
  4. Next, specify the AlternativeTextTitle and AlternativeTextDescription properties.
  5. After that, add the Image to the Page using the AppendChildLast() method.
  6. Similarly, add the Page to the Document.
  7. Finally, call the Save() method to save the OneNote document.

The following code sample shows how to insert an image with alternative text in OneNote using C#.

Get a Free License

You can get a free temporary license to try the library without evaluation limitations.

Conclusion

In this article, we have learned how to:

  • create a new OneNote document using C#;
  • load an existing OneNote document;
  • add a page to the OneNote document;
  • add an image to OneNote document Page programmatically;

Besides adding an image to a OneNote in C#, you can learn more about Aspose.Note for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also