We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Adding text to textbox

Hi,
I have docx with some text boxes in that. I want to insert text in text boxes without replacing text boxes
Thanks.

@kxk010,

Please try using the following code. Hope, this helps in achieving what you are looking for:

Document doc = new Document();

Shape plainTextShape = new Shape(doc, ShapeType.TextPlainText);

plainTextShape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
plainTextShape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
plainTextShape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
plainTextShape.VerticalAlignment = VerticalAlignment.Center;

plainTextShape.Width = 300;
plainTextShape.Height = 70;

plainTextShape.TextPath.Text = "The Text inside Shape";

plainTextShape.Name = string.Format("Name_{0}", Guid.NewGuid());
plainTextShape.WrapType = WrapType.None;

doc.FirstSection.Body.FirstParagraph.AppendChild(plainTextShape);

/////////////////
Shape anotherShape = new Shape(doc, ShapeType.TextBox);
anotherShape.WrapType = WrapType.Inline;
anotherShape.Width = 300;
anotherShape.Height = 70;

Paragraph para = new Paragraph(doc);
Run runText = new Run(doc, "This is inline Text Box");
para.AppendChild(runText);

anotherShape.AppendChild(para);
doc.FirstSection.Body.FirstParagraph.AppendChild(anotherShape);

doc.Save("E:\\Temp\\19.5.docx");

In case the problem still remains, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Aspose.Words 19.5 generated output document showing the undesired behavior (if any)
  • Your expected document showing the correct output. You can create expected document by using MS Word.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you code to achieve the same by using Aspose.Words. Thanks for your cooperation.