Convert OneNote Document to PDF using Java

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:

  1. OneNote to PDF Converter Java API
  2. Convert Existing OneNote Document to PDF
  3. Create OneNote Document and Convert it to PDF
  4. Convert Range of OneNote Pages to PDF
  5. Convert OneNote to PDF with Image Compression

OneNote to PDF Converter Java 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:

  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 Java.

Convert Existing OneNote Document to PDF using Java

Convert Existing OneNote Document to 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:

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

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

  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 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.

See Also