OneNote is a digital notebook that allows collecting, organizing, and collaborating notes, drawings, screen clippings, and audio commentaries. In certain cases, we may need to export the content of OneNote documents into PDF documents. It allows sharing handouts with someone who doesn’t have OneNote. 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 using Java.
The following topics shall be covered in this article:
- OneNote to PDF Converter Java 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
Java OneNote to PDF Converter API
For converting OneNote documents to PDF, we will be using the Aspose.Note for Java API. It allows creating, reading, and converting OneNote documents programmatically without using Microsoft OneNote.
The Document class of the API represents a Onenote document. It provides various methods and properties to work with the OneNote document. The save() method of this class allows saving the OneNote document on this disk in a specified format. The Page class represents a page in the OneNote document. The PdfSaveOptions class of the API provides options for creating the PDF such as PageIndex, PageCount and others.
Please either download the JAR of the API or add the following pom.xml configuration in a Maven-based Java application.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-note</artifactId>
<version>22.3</version>
<classifier>jdk17</classifier>
</dependency>
Convert Existing OneNote Document to PDF
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 Java.
Create OneNote Document and Convert to PDF
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 Java.
Convert Range of OneNote Pages to PDF
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 Java.
Convert OneNote to PDF with Image Compression
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 Java.
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 Java;
- save the OneNote document as a PDF programmatically;
- export Notes from a OneNote document to PDF and compress images.
Besides, you can learn more about Aspose.Note for Java API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.