Working with Tags

Get Note Tag Details from OneNote Document

The NoteTag class provides all the properties related to a note tag in a Microsoft OneNote document. All the OneNote file’s note tags are contained by RichText nodes of the Document object.

The OneNote file displaying a note tag.

todo:image_alt_text

The code below shows how to get details about each note tag from the OneNote document.

 1String dataDir = Utils.getSharedDataDir(GetNodeTags.class) + "tags/";
 2
 3// Load the document into Aspose.Note
 4Document doc = new Document(dataDir + "Sample1.one");
 5
 6// Get all RichText nodes
 7List<RichText> nodes = doc.getChildNodes(RichText.class);
 8
 9// Iterate through each node
10for (RichText richText : nodes) {
11	for (NoteTagCore tag : richText.getTags()) {
12		if (tag.getClass() == NoteTag.class) {
13			NoteTag noteTag = (NoteTag) tag;
14			// Retrieve properties
15			System.out.println("Completed Time: " + noteTag.getCompletedTime());
16			System.out.println("Create Time: " + noteTag.getCreationTime());
17			System.out.println("Font Color: " + noteTag.getFontColor());
18			System.out.println("Status: " + noteTag.getStatus());
19			System.out.println("Label: " + noteTag.getLabel());
20			System.out.println("Icon: " + noteTag.getIcon());
21			System.out.println("High Light: " + noteTag.getHighlight());
22		}
23	}
24}

Tag Important Notes in the OneNote Document

The NoteTag class provides all the properties related to a note tag. Users can now tag text, image, and tables. Aspose.Note for Java API supports all these feature operations.

These articles show how to:

Add a New Text Node with a Tag

The code below shows how to add a new text node with a tag in the OneNote document.

 1// The path to the documents directory.
 2String dataDir = Utils.getSharedDataDir(AddTextNodeWithTag.class) + "tags/";
 3
 4// Create an object of the Document class
 5Document doc = new Document();
 6// Initialize Page class object
 7Page page = new Page(doc);
 8// Initialize Outline class object
 9Outline outline = new Outline(doc);
10// Initialize OutlineElement class object
11OutlineElement outlineElem = new OutlineElement(doc);
12
13ParagraphStyle textStyle = new ParagraphStyle();
14textStyle.setFontColor(Color.BLACK);
15textStyle.setFontName("Arial");
16textStyle.setFontSize(10);
17
18RichText text = new RichText(doc);
19text.setText("OneNote text.");
20text.setParagraphStyle(textStyle);
21
22NoteTag noteTag = new NoteTag();
23noteTag.setIcon(TagIcon.YellowStar);
24text.getTags().addItem(noteTag);
25
26// Add text node
27outlineElem.appendChildLast(text);
28// Add outline element node
29outline.appendChildLast(outlineElem);
30// Add outline node
31page.appendChildLast(outline);
32// Add page node
33doc.appendChildLast(page);
34
35dataDir = dataDir + "AddTextNodeWithTag_out.one";
36// Save OneNote document
37doc.save(dataDir);

Add a New Image Node with a Tag

The code below shows how to add a new Image node with a tag in the OneNote document.

 1String dataDir = Utils.getSharedDataDir(AddNewImageNodeWithTag.class) + "tags/";
 2
 3// create an object of the Document class
 4Document doc = new Document();
 5// initialize Page class object
 6Page page = new Page(doc);
 7// initialize Outline class object
 8Outline outline = new Outline(doc);
 9// initialize OutlineElement class object
10OutlineElement outlineElem = new OutlineElement(doc);
11// load an image
12Image image = new Image(doc, dataDir + "Input.jpg");
13// insert image in the document node
14outlineElem.appendChildLast(image);
15NoteTag noteTag = new NoteTag();
16noteTag.setIcon(TagIcon.YellowStar);
17image.getTags().add(noteTag);
18
19// add outline element node
20outline.appendChildLast(outlineElem);
21// add outline node
22page.appendChildLast(outline);
23// add page node
24doc.appendChildLast(page);
25// save OneNote document
26doc.save(dataDir + "AddNewImageNodeWithTag_out.pdf", SaveFormat.Pdf);

Add a New Table Node with a Tag

The code below shows how to add a new Table node with a tag in the OneNote document.

 1String dataDir = Utils.getSharedDataDir(AddNewTableNodeWithTag.class) + "tags/";
 2// create an object of the Document class
 3Document doc = new Document();
 4// initialize Page class object
 5Page page = new Page(doc);
 6// initialize TableRow class object
 7TableRow row = new TableRow(doc);
 8// initialize TableCell class object
 9TableCell cell = new TableCell(doc);
10// add cell to row node
11row.appendChildLast(cell);
12// initialize table node
13Table table = new Table(doc);
14table.setBordersVisible(true);
15TableColumn column = new TableColumn();
16column.setWidth(70);
17table.getColumns().addItem(column);
18
19// insert row node in table
20table.appendChildLast(row);
21// add tag to this table node
22NoteTag noteTag = new NoteTag();
23noteTag.setIcon(TagIcon.QuestionMark);
24table.getTags().add(noteTag);
25
26Outline outline = new Outline(doc);
27OutlineElement outlineElem = new OutlineElement(doc);
28// add table node
29outlineElem.appendChildLast(table);
30// add outline elements
31outline.appendChildLast(outlineElem);
32page.appendChildLast(outline);
33doc.appendChildLast(page);
34// save OneNote document
35doc.save(dataDir + "AddNewTableNodeWithTag_out.pdf", SaveFormat.Pdf);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.