Change Text Style in OneNote using Java | Change Font Style

Microsoft OneNote is a powerful note-taking tool. Take your OneNote experience to the next level by learning how to change styles using Java! In this guide, we’ll show you how to change styles in OneNote documents using Java to enhance readability. This guide will provide you with step-by-step instructions for implementing style changes and code snippets to enhance your productivity.

This article covers the following topics:

  1. Java OneNote API to change styles in OneNote
  2. Create a page title with text style
  3. Change the text style of a page title
  4. Change the text style of paragraphs
  5. Set the default paragraph style
  6. Free learning resources

Java OneNote API to Change Styles in OneNote

Aspose.Note for Java OneNote API provides a powerful way to interact with OneNote documents programmatically. It allows developers to automate tasks, create custom tools, and integrate OneNote with other applications in Java. To change styles in OneNote using Java, we will use Aspose.Note for Java OneNote API to access and modify the formatting of notes.

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

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository> 
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-note</artifactId>
    <version>24.4</version>
    <classifier>jdk17</classifier>
</dependency>

Create OneNote Page Title with Text Style in Java

We can create a page title in a OneNote document programmatically by following the steps below:

  1. Create a new OneNote document using the Document class.
  2. Add a new page using the Page class.
  3. Specify the title text, date, and time using the RichText class.
  4. Set the ParagraphStyle property of the RichText class object to define its font name, size, color, etc.
  5. Finally, save the document using the save() method.

The following code sample shows how to create a page title with styles in a OneNote document using Java.

Create OneNote Page Title with Text Style in Java

Create OneNote Page Title with Text Style in Java.

Change Text Style of a Page Title in Java

We can also change the text style of page titles in OneNote documents by following the steps below:

  1. Load an existing OneNote document using the Document class.
  2. Loop through all the page titles in a document.
  3. Modify the ParagraphStyle properties for each title.
  4. Alternatively, modify the Style properties of TextRuns for each title.
  5. Finally, save the document using the save() method.

The following code sample shows how to change the text style of a page title in a OneNote document using Java.

Change Text Style of a Page Title in Java

Change Text Style of a Page Title in Java.

Change Text Style of OneNote Paragraphs in Java

We can change the text style of paragraphs in OneNote documents by following the steps below:

  1. Load the OneNote document using the Document class.
  2. Get a particular or all RichText nodes using the GgtChildNodes() method.
  3. Modify the Style properties, e.g. FontColor, Highlight, FontSize, etc. of TextRuns for the RichText node(s).
  4. Finally, save the document using the save() method.

The following code sample shows how to change the text style of a paragraph in a OneNote document using Java.

Change Text Style of OneNote Paragraphs in Java

Change Text Style of OneNote Paragraphs in Java.

Set Default Paragraph Style in OneNote using Java

We can also set a default paragraph style in a OneNote document by following the steps below:

  1. Create a new document using the Document class.
  2. Create a new page using the Page class.
  3. Initialize Outline and OutlineElement class objects.
  4. Create a RichText class object and specify ParagraphStyle.
  5. After that, append child elements.
  6. Finally, save the document using the save() method.

The following code sample shows how to set the default paragraph style of a paragraph in a OneNote document using Java.

Get a Free License

Get a free temporary license to unlock unrestricted editing of text and font styles in OneNote documents. Simply visit the Temporary License page, follow the instructions, and receive your complimentary license to explore the full potential of Aspose.Note for Java OneNote API.

OneNote Edit Styles – Free Resources

  1. Read the Working with Text Styles section of the official documentation to learn more about styling.
  2. Read the Working with Text section to learn how to work with various text elements in Java.

Besides editing text and font styles in a OneNote document, explore various other features of the API using the resources below:

Conclusion

In this article, we explored how to change the text styles of page titles or paragraphs in OneNote documents using Java. By leveraging Aspose.Note for Java OneNote API, you can easily integrate such functionality into your Java applications. So, let’s dive in and start customizing OneNote to better fit your needs!

In case of any ambiguity, please feel free to contact us on our free support forum.

See Also