Apply Numbering on Text in Aspose.Note

Introduction

Aspose.Note for .NET provides powerful tools for document manipulation in C# applications. In this tutorial, we will explore the process of applying numbering on text using Aspose.Note. Follow these step-by-step instructions to enhance your document formatting effortlessly.

Prerequisites

Before diving into the tutorial, ensure you have the following prerequisites in place:

  • Basic understanding of C# programming language.
  • Aspose.Note for .NET installed. You can download it here.
  • An integrated development environment (IDE) such as Visual Studio.

Import Namespaces

To get started, make sure to import the necessary namespaces in your C# project:

using System;
using System.Globalization;
using System.IO;
using Aspose.Note;
using System.Drawing;
using System.Collections.Generic;

Step 1: Set Up Your Document

Begin by creating a new document and initializing the required objects:

// The path to the documents directory.
string dataDir = "Your Document Directory";
// Create an object of the Document class
Document doc = new Document();
// Initialize Page class object
Aspose.Note.Page page = new Aspose.Note.Page(doc);
// Initialize Outline class object
Outline outline = new Outline(doc);

Step 2: Define Default Style

Set up the default styling for your text using the ParagraphStyle class:

ParagraphStyle defaultStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };

Step 3: Apply Numbering

Initialize OutlineElement class objects and apply numbering to each element:

OutlineElement outlineElem1 = new OutlineElement(doc) { NumberList = new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10) };
RichText text1 = new RichText(doc) { Text = "First", ParagraphStyle = defaultStyle };
outlineElem1.AppendChildLast(text1);
OutlineElement outlineElem2 = new OutlineElement(doc) { NumberList = new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10) };
RichText text2 = new RichText(doc) { Text = "Second", ParagraphStyle = defaultStyle };
outlineElem2.AppendChildLast(text2);
OutlineElement outlineElem3 = new OutlineElement(doc) { NumberList = new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10) };
RichText text3 = new RichText(doc) { Text = "Third", ParagraphStyle = defaultStyle };
outlineElem3.AppendChildLast(text3);

Step 4: Add Outline Elements

Append the outline elements to the outline:

outline.AppendChildLast(outlineElem1);
outline.AppendChildLast(outlineElem2);
outline.AppendChildLast(outlineElem3);

Step 5: Save the Document

Save the OneNote document with the applied numbering:

dataDir = dataDir + "ApplyNumberingOnText_out.one"; 
doc.Save(dataDir);
Console.WriteLine("\nNumbering applied successfully on a text.\nFile saved at " + dataDir); 

Conclusion

Congratulations! You’ve successfully learned how to apply numbering on text in Aspose.Note for .NET. Experiment with different formatting options to create visually appealing documents effortlessly.

FAQ’s

1. Can I customize the numbering format?

Yes, the NumberList class allows you to customize the numbering format according to your preferences.

2. Are there other formatting options available?

Aspose.Note provides a wide range of formatting options, including font styling, color, and more.

3. Is Aspose.Note compatible with Visual Studio?

Absolutely! Aspose.Note seamlessly integrates with Visual Studio for a smooth development experience.

4. Can I try Aspose.Note before purchasing?

Certainly! You can explore a free trial here.

5. Where can I get support for Aspose.Note?

For any assistance or queries, visit the Aspose.Note forum.