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:
- C# OneNote to PDF Converter API
- Convert Existing OneNote Document to PDF
- Create OneNote Document and Convert it to PDF
- Convert Range of OneNote Pages to PDF
- Convert OneNote to PDF with Image Compression
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:
- Load a OneNote file using the Document class.
- 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#.
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:
- Firstly, create an instance of the Document class.
- Next, create a new page using the Page class object.
- Then, add the newly created 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 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:
- Firstly, load a OneNote file using the Document class.
- Next, define PdfSaveOptions 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 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:
- Firstly, load a OneNote file using the Document class.
- Next, define PdfSaveOptions class object.
- Then, set the ImageCompression type as JPEG.
- After that, set the quality for JPEG compression using the JpegQuality.
- 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 converting OneNote to PDF in C#, you can learn more about Aspose.Note for .NET API using documentation. In case of any ambiguity, please feel free to contact us on our free support forum.