Insert PDF into OneNote using Java

Microsoft OneNote is a popular digital note-taking tool. Beyond its capabilities in gathering, structuring, and enabling collaborative work, it facilitates teamwork through shared notes, drawings, screen snippets, and audio annotations. In certain cases, we may need to attach PDF files to OneNote documents. In this article, we will learn how to insert a PDF document into OneNote using Java.

This article covers the following topics:

  1. Java API to Insert PDF into OneNote
  2. Insert PDF into a New OneNote Document
  3. Insert PDF into an Existing OneNote Document
  4. Free Learning Resources

Java API to Insert PDF into OneNote

We will use Aspose.Note for Java for inserting PDF documents in OneNote. It allows developers to work with Microsoft OneNote files (both .one and .onetoc2 formats) programmatically using Java. With Aspose.Note for Java, you can create, read, manipulate, and convert OneNote documents in your Java applications without having to rely on Microsoft Office or other external dependencies.

Please download the JAR of the API or add the following pom.xml configuration to a Maven-based Java application.

    <name>Aspose Java API</name>

Insert PDF in a New OneNote Document using Java

We can easily create a new OneNote document and insert a PDF file as an attachment by following the steps given below:

  1. Create an instance of the Document class.
  2. Create objects of the Page, Outline, and OutlineElement classes.
  3. Initialize the AttachedFile class object and pass the file name and stream object of an icon as arguments.
  4. After that, add the AttachedFile to the OutlineElement using the appendChildLast() method.
  5. Similarly, append Outline to the Page and Page to the Document.
  6. Finally, call the save() method to save the OneNote document.

The following code sample shows how to insert a PDF file into a new OneNote document using Java.

Insert PDF into New OneNote Document using Java

Insert PDF into New OneNote Document using Java.

Insert PDF in an Existing OneNote Document in Java

Similarly, we can insert a PDF document into an existing OneNote document by following the steps mentioned above. However, we just need to load an existing OneNote using the Document class in the step # 1.

The following code sample shows how to insert a PDF to an existing OneNote document using Java.

Get a Free License

You can get a free temporary license to try the library without evaluation limitations.

Attach PDF to OneNote – Free Learning Resources

You can learn more about inserting PDFs into OneNote and explore other features of Aspose.Note for Java using the resources below:


In this article, we learned how to insert a PDF document into OneNote using Java. Incorporating PDFs into OneNote using Java provides a streamlined and efficient way to enhance your note-taking and documentation processes. By following the steps outlined in this article, you can empower your Java applications with the ability to effortlessly import PDFs, fostering a more organized and comprehensive note-taking experience. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also