How to create a new page in the existing OneNote book

I want to add new pages to the existing OneNote book using Aspose.Note component. I use C#. Please suggest me to do the same.

@SurinderH,

See the following sample code on how to add new pages to the document for your reference.
e.g.
Sample code:

// Create an object of the Document class
Aspose.Note.Document doc = new Aspose.Note.Document("g:\\test2\\Document1.one");

// Add first page
Aspose.Note.Page page1 = new Aspose.Note.Page();
// Initialize Outline class object
Aspose.Note.Outline outline1 = new Aspose.Note.Outline();
// Initialize OutlineElement class object
Aspose.Note.OutlineElement outlineElem1 = new Aspose.Note.OutlineElement();
// Initialize TextStyle class object and set formatting properties
Aspose.Note.ParagraphStyle textStyle1 = new Aspose.Note.ParagraphStyle { FontColor = System.Drawing.Color.Black, FontName = "Arial", FontSize = 10 };
//Set the string
string data1 = "this is text new page1";
// Initialize RichText class object and apply text style
Aspose.Note.RichText richText1 = new Aspose.Note.RichText() { Text = data1, ParagraphStyle = textStyle1 };
// Add RichText node
outlineElem1.AppendChildLast(richText1);
// Add OutlineElement node
outline1.AppendChildLast(outlineElem1);
// Add Outline node
page1.AppendChildLast(outline1);

// Add second page
Aspose.Note.Page page2 = new Aspose.Note.Page();
// Initialize Outline class object
Aspose.Note.Outline outline2 = new Aspose.Note.Outline();
// Initialize OutlineElement class object
Aspose.Note.OutlineElement outlineElem2 = new Aspose.Note.OutlineElement();
// Initialize TextStyle class object and set formatting properties
Aspose.Note.ParagraphStyle textStyle2 = new Aspose.Note.ParagraphStyle { FontColor = System.Drawing.Color.Black, FontName = "Arial Black", FontSize = 12 };
//Set the string
string data2 = "this is text new page2";
// Initialize RichText class object and apply text style
Aspose.Note.RichText richText2 = new Aspose.Note.RichText() { Text = data2, ParagraphStyle = textStyle2 };
// Add RichText node
outlineElem2.AppendChildLast(richText2);
// Add OutlineElement node
outline2.AppendChildLast(outlineElem2);
// Add Outline node
page2.AppendChildLast(outline2);

// Add Pages to document
doc.AppendChildLast(page1);
doc.AppendChildLast(page2);

// Save OneNote document
doc.Save("g:\\test2\\out1.one");

Also, see the document on working with pages for your reference.

Hope, this helps a bit.

Thanks Amjad.

You have opened a notebook Document1.one and then saved the changes to out1.one.

Is it not possible to save the changes to existing notebook Document1.one instead of new one?

Can we define the width of the text to insert the long paragraph in multiple lines?

@SurinderH,

You may simply use the line:

// Save OneNote document
doc.Save("g:\\test2\\Document1.one");

You may specify font attributes for it. To insert multiple lines, see the sample code:
e.g.

var page = new Page();
var outline = new Outline();
var outlineElem = new OutlineElement();

var text = new RichText() { ParagraphStyle = new ParagraphStyle() { FontName = "Courier New", FontSize = 20 } }
                .Append($"DefaultParagraphFontAndSize{Environment.NewLine}")
                .Append($"OnlyDefaultParagraphFont{Environment.NewLine}", new TextStyle() { FontSize = 14 })
                .Append("OnlyDefaultParagraphFontSize", new TextStyle() { FontName = "Verdana" });

outlineElem.AppendChildLast(text);
outline.AppendChildLast(outlineElem);
page.AppendChildLast(outline);
document.AppendChildLast(page);

Also, see the document for your reference.

Hope, this helps a bit.

Many thanks Amjad.

@SurinderH,

You are welcome.