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:
- C# API to Add Images to OneNote
- Add Image to a New OneNote Document
- Insert Image into an Existing OneNote Document
- 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:
- Firstly, create an instance of the Document class.
- Next, initialize the Page class object.
- Then, load an image using the Image class.
- Optionally, set image height, width, alignment, offset, etc.
- After that, add the Image to the Page using the AppendChildLast() method.
- Similarly, add the Page to the Document.
- 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 Existing OneNote Document in C#
We can also insert an image into an existing OneNote document by following the steps given below:
- Firstly, load an existing OneNote using the Document class.
- Next, initialize the Page class object.
- Then, load an image using the Image class.
- Optionally, set image height, width, alignment, offset, etc.
- After that, add the Image to the Page using the AppendChildLast() method.
- Similarly, add the Page to the Document.
- 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:
- Firstly, create an instance of the Document class.
- Next, initialize the Page class object.
- Then, load an image using the Image class.
- Next, specify the AlternativeTextTitle and AlternativeTextDescription properties.
- After that, add the Image to the Page using the AppendChildLast() method.
- Similarly, add the Page to the Document.
- 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.