Convert OneNote to PDF in C#

OneNote document is a digital notebook used to collect, organize, and collaborate free form information and multi-user collaboration in the form of notes, drawings, screen clippings, and audio commentaries. In certain cases, we may need to export the content of OneNote documents into PDF documents. PDF is the most popular format for sharing and printing documents without losing the formatting. In this article, we will learn how to convert a OneNote document to a PDF in C#.

The following topics shall be covered in this article:

OneNote to PDF Converter C# API

For converting OneNote documents to PDF, we will be using the Aspose.Note for .NET API. It allows creating, reading, and converting OneNote documents programmatically without using Microsoft OneNote. Please either download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.Note

Convert Existing OneNote Document to PDF in C#

We can convert an existing OneNote document to a PDF 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 a PDF. It takes the output PDF file path and the Save Format as arguments.

The following code sample shows how to convert an existing OneNote document to a PDF using C#.

Convert Existing OneNote Document to PDF using C#

Convert Existing OneNote Document to PDF using C#.

Create OneNote Document and Convert to PDF in C#

We can create a OneNote document and convert it to a PDF 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 newly created 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 a PDF. It takes the output PDF file path as an argument.

The following code sample shows how to create a OneNote document and convert it to a PDF using C#.

Convert Range of OneNote Pages to PDF in C#

We can convert a range of pages from a OneNote document to a PDF by following the steps given below:

  1. Firstly, load a OneNote file using the Document class.
  2. Next, define PdfSaveOptions 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 a PDF. It takes the output PDF file path and PdfSaveOptions as arguments.

The following code sample shows how to convert a range of pages from a OneNote document to a PDF using C#.

Convert OneNote to PDF with Image Compression in C#

We can compress images of a OneNote document while converting it to a PDF document by following the steps given below:

  1. Firstly, load a OneNote file using the Document class.
  2. Next, define PdfSaveOptions class object.
  3. Then, set the ImageCompression type as JPEG.
  4. After that, set the quality for JPEG compression using the JpegQuality.
  5. Finally, call the Save() method to save the OneNote document as a PDF. It takes the output PDF file path and PdfSaveOptions as arguments.

The following code sample shows how to convert a OneNote document to a PDF and apply image compression 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 a PDF programmatically;
  • export a OneNote document to PDF and compress images.

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