
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:
- Java OneNote API to change styles in OneNote
- Create a page title with text style
- Change the text style of a page title
- Change the text style of paragraphs
- Set the default paragraph style
- 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:
- Create a new OneNote document using the Document class.
- Add a new page using the Page class.
- Specify the title text, date, and time using the RichText class.
- Set the ParagraphStyle property of the RichText class object to define its font name, size, color, etc.
- 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.
// initialize new Document | |
Document doc = new Document(); | |
// initialize new Page | |
Page page = new Page(); | |
// title text | |
RichText titleText = new RichText().append("Title text."); | |
// title text style | |
ParagraphStyle titleTextStyle = new ParagraphStyle(); | |
titleTextStyle.setFontName("Courier New"); | |
titleTextStyle.setFontSize(20); | |
// set title text style | |
titleText.setParagraphStyle(titleTextStyle); | |
// title date | |
RichText titleDate = new RichText().append("Friday, 11 November 2011"); | |
titleDate.setParagraphStyle(ParagraphStyle.getDefault()); | |
// title time | |
RichText titleTime = new RichText().append("12:34"); | |
titleTime.setParagraphStyle(ParagraphStyle.getDefault()); | |
Title title = new Title(); | |
title.setTitleText(titleText); | |
title.setTitleDate(titleDate); | |
title.setTitleTime(titleTime); | |
page.setTitle(title); | |
// append page node | |
doc.appendChildLast(page); | |
// save the document | |
doc.save("CreatePageTitle.one"); |

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:
- Load an existing OneNote document using the Document class.
- Loop through all the page titles in a document.
- Modify the ParagraphStyle properties for each title.
- Alternatively, modify the Style properties of TextRuns for each title.
- 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.
// Load the document into Aspose.Note. | |
Document document = new Document("CreatePageTitle.one"); | |
// Change the style | |
for (Title title : (Iterable<Title>) document.getChildNodes(Title.class)) { | |
// Modify title paragraph style | |
title.getTitleText().getParagraphStyle().setFontSize(38); | |
title.getTitleText().getParagraphStyle().setBold(true); | |
title.getTitleText().getParagraphStyle().setFontColor(Color.BLUE); | |
// Alternatively modify text run style within the title | |
for (TextRun richText : title.getTitleText().getTextRuns()) { | |
richText.getStyle().setFontSize(50); | |
richText.getStyle().setBold(true); | |
richText.getStyle().setFontColor(Color.BLUE); | |
} | |
} | |
// Save the document | |
document.save("PageTitle.one"); |

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:
- Load the OneNote document using the Document class.
- Get a particular or all RichText nodes using the GgtChildNodes() method.
- Modify the Style properties, e.g. FontColor, Highlight, FontSize, etc. of TextRuns for the RichText node(s).
- 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.
// Load the document into Aspose.Note. | |
Document document = new Document("D:\\Files\\Aspose.one"); | |
// Get all the pages | |
List<Page> pages = document.getChildNodes(Page.class); | |
// Get a particular RichText node(s) | |
List<RichText> richTextNodes = pages.get(3).getChildNodes(RichText.class); | |
if (richTextNodes != null && richTextNodes.size() > 3) { | |
for (int i = 3; i < richTextNodes.size(); i++) { | |
RichText richText = richTextNodes.get(i); | |
// Apply formatting style | |
for (TextRun run : richText.getTextRuns()) { | |
// Set font color | |
run.getStyle().setFontColor(Color.YELLOW); | |
// Set highlight color | |
run.getStyle().setHighlight(Color.BLUE); | |
// Set font size | |
run.getStyle().setFontSize(14); | |
} | |
} | |
} | |
// Save the document | |
document.save("D:\\Files\\ParagraphStyle.one"); |

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:
- Create a new document using the Document class.
- Create a new page using the Page class.
- Initialize Outline and OutlineElement class objects.
- Create a RichText class object and specify ParagraphStyle.
- After that, append child elements.
- 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.
// Create a new document | |
Document document = new Document(); | |
// Create a new page | |
Page page = new Page(); | |
// Create a new outline | |
Outline outline = new Outline(); | |
// Create an outline element | |
OutlineElement outlineElem = new OutlineElement(); | |
// Create style | |
ParagraphStyle defaultStyle = new ParagraphStyle() | |
.setFontName("Courier New") | |
.setFontSize(20); | |
RichText text = new RichText() | |
.append("DefaultParagraphFontAndSize") | |
.append(System.lineSeparator()) | |
.append("OnlyDefaultParagraphFont", new TextStyle().setFontSize(14)) | |
.append(System.lineSeparator()) | |
.append("OnlyDefaultParagraphFontSize", new TextStyle().setFontName("Verdana")); | |
text.setParagraphStyle(defaultStyle); | |
// Append elements | |
outlineElem.appendChildLast(text); | |
outline.appendChildLast(outlineElem); | |
page.appendChildLast(outline); | |
document.appendChildLast(page); | |
// Save the document | |
document.save("SetDefaultParagraphStyle.one"); |
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
- Read the Working with Text Styles section of the official documentation to learn more about styling.
- 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.