How to add a new textbox for a page at given position?

Hi, Support:
Would you help me to add a new textbox for a page at given position? and then add texts into the textbox, set fontname,fontsize,fontcolor for the texts in the textbox, and then set the boarder of the textbox for none, and set the line charatcter space to a given value such as -30.
How to work for this?
Thanks!

@ducaisoft You can use code like the following to create a textbox:

Document doc = new Document();

// Create a textbox shape.
Shape textBox = new Shape(doc, ShapeType.TextBox);
// Specify size in points.
textBox.Width = 300;
textBox.Height = 300;
// Specify position.
textBox.WrapType = WrapType.None;
textBox.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
textBox.RelativeVerticalPosition = RelativeVerticalPosition.Page;
// You can also specify alignmenr if you for example need to place text box in the middle of the page.
//textBox.VerticalAlignment = VerticalAlignment.Center;
//textBox.HorizontalAlignment = HorizontalAlignment.Center;
textBox.Top = 500;
textBox.Left = 100;
// Set border to none
textBox.Stroked = false;

// Create a paragraph for ttextbox content.
Paragraph para = new Paragraph(doc);
para.ParagraphFormat.LineSpacing = 30;
// Create Run for the text and sert font properties.
Run run = new Run(doc);
run.Font.Size = 16;
run.Font.Color = Color.Red;
run.Font.Name = "Arial";
run.Text = "This is Arial red text with 16 font size";
// Put Run into the paragraph and paragraph into the textbox.
para.AppendChild(run);
textBox.AppendChild(para);

// Insert the text box into the document.
doc.FirstSection.Body.FirstParagraph.AppendChild(textBox);

doc.Save(@"C:\Temp\out.docx");

Also, please see our documentation to learn more about working with graphics objects.

Thanks!
Other questions are that:
If a doc has 10 pages, how to do:

  1. extract all the texts in the given page,such as the second page. Maybe need to extract the second page and then extract its texts?
  2. how to add the textbox into the second page? there is no method for the builder to move cursor to a given page, and there is no feature for Node.NodeType=NodeType.Page

Is there any way to work for those?

@ducaisoft There is no concept of page in MS Word documents. MS Word documents are flow documents, more like HTML or TXT documents. Pages are build on the fly by the consumer application or upon rendering the document. Aspose.Words uses it’s own layout engine to layout document into pages.

  1. To extract content of a particular page you can use Document.ExtractPages method.
  2. You can use LayoutCollector class to detect where page start or ends. In your case you should detect a paragraph that is on the second page and insert the created shape into this paragraph.

Also, please note to properly build document layout Aspose.Words requires the fonts used in the source document. If Aspose.Words cannot find the required fonts, the fonts are substituted. This might lead into layout differences.