Convert OneNote Document to HTML Webpage using C#

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 export a OneNote document to HTML in C#.

The following topics shall be covered in this article:

C# API to Export OneNote to HTML

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:

  1. Firstly, create an instance of the Document class.
  2. Next, create a new page using the Page class object.
  3. Then, add the Page to the document using the AppendChildLast() method.
  4. After that, add content such as Page Title, etc.
  5. 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#.

Create OneNote Document and Convert to HTML Webpage using C#

Create OneNote Document and Convert to HTML Webpage using C#.

Export Existing OneNote Document to HTML using C#

We can also export an existing OneNote document to an HTML webpage by following the steps given below:

  1. Load a OneNote file using the Document class.
  2. 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 export an existing OneNote document to HTML using C#.

Convert Existing OneNote Document to HTML using C#

Convert Existing OneNote Document to HTML using C#

Export 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:

  1. Firstly, load a OneNote file using the Document class.
  2. Next, define HtmlSaveOptions class object.
  3. Then, set the PageIndex from where to start the conversion.
  4. After that, set PageCount to convert a total number of pages.
  5. 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 export 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:

  1. Firstly, load a OneNote file using the Document class.
  2. Next, define HtmlSaveOptions class object.
  3. After that, set the ExportCss, ExportFonts, and ExportImages properties to ResourceExportType.ExportEmbedded.
  4. 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.

See Also