OneNote document is a digital notebook used to collect, organize, and collaborate notes and ideas. In certain cases, we may need to export the content of OneNote documents into HTML web pages. HTML web pages can be viewed in any browser available on digital devices. Converting OneNote to HTML allows showing the content in any browser without sharing the original files. In this article, we will learn how to convert a OneNote document to an HTML webpage using C#.
The following topics shall be covered in this article:
- OneNote to HTML Converter C# API
- Create OneNote Document and Convert to HTML Webpage
- Convert Existing OneNote Document to HTML
- Convert Specific Pages of OneNote to HTML
- Save OneNote to HTML with Embedded Resources
OneNote to HTML Converter C# API
For converting OneNote documents to HTML webpages, we will be using the Aspose.Note for .NET API. It is a feature-rich OneNote document manipulation API that lets you create, read, and convert OneNote documents programmatically. Please either download the DLL of the API or install it using NuGet.
PM> Install-Package Aspose.Note
Create OneNote Document and Convert to HTML Webpage using C#
We can create a OneNote document and convert it to an HTML webpage programmatically by following the steps given below:
- Firstly, create an instance of the Document class.
- Next, create a new page using the Page class object.
- Then, add the Page to the document using the AppendChildLast() method.
- After that, add content such as Page Title, etc.
- Finally, call the Save() method to save the OneNote document as HTML. It takes the output HTML file path as an argument.
The following code sample shows how to create a OneNote document and Convert it to HTML using C#.
Convert Existing OneNote Document to HTML using C#
We can also convert an existing OneNote document to an HTML webpage by following the steps given below:
- Load a OneNote file using the Document class.
- Call the Save() method to save the OneNote document as HTML. It takes the output HTML file path and SaveFormat as arguments.
The following code sample shows how to convert an existing OneNote document to HTML using C#.
Convert Specific Pages of OneNote to HTML using C#
We can convert a range of specific pages from a OneNote document to an HTML webpage by following the steps given below:
- Firstly, load a OneNote file using the Document class.
- Next, define HtmlSaveOptions class object.
- Then, set the PageIndex from where to start the conversion.
- After that, set PageCount to convert a total number of pages.
- Finally, call the Save() method to save the OneNote document as HTML. It takes the output HTML file path and HtmlSaveOptions as arguments.
The following code sample shows how to convert a range of pages from a OneNote document to HTML using C#.
Save OneNote to HTML with Embedded Resources using C#
When converting a OneNote document to an HTML webpage, the default way to store resources like fonts, images, and CSS is in external files in an output folder. We can convert a OneNote document to an HTML webpage and embed all the resources inline by following the steps given below:
- Firstly, load a OneNote file using the Document class.
- Next, define HtmlSaveOptions class object.
- After that, set the ExportCss, ExportFonts, and ExportImages properties to ResourceExportType.ExportEmbedded.
- Finally, call the Save() method to save the OneNote document as HTML. It takes the output HTML file path and HtmlSaveOptions as arguments.
The following code sample shows how to convert a OneNote document to HTML by embedding all resources 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#;
- save the OneNote document as HTML programmatically;
- export a OneNote document to HTML and embed images, fonts, and CSS inline.
Besides, 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 the forum.