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

Free Support Forum - aspose.com

Cannot assign text to TextBox element [RESOLVED]

I have been trying to set the text of a TextBox for quite some time now without any luck. I’ve tried both the “Builder.Write()” approach, and the textbox.TextPath.Text route. Neither work. The TextBox Shape is always empty.


Any thoughts?

Paragraph parentPara = (Paragraph)run.ParentNode;

Shape textbox = new Shape(doc, ShapeType.TextBox);
textbox.Stroked = false;
textbox.Width = 40;
textbox.Height = 40;
textbox.Fill.Opacity = 0;
textbox.BehindText = true;
textbox.TextPath.Text = “TEST”;

parentPara.AppendChild(textbox);

Just figured out how to get around this. I just created a paragraph and a run with the numbering and appended it to the TextBox.


In the examples I was able to find on the Aspose forums, I have not seen this as a requirement, so if anyone understands this subject better than I, please let us know whether inserting a paragraph inside a TextBox is required in order to get text to render.

[…snip…]
Paragraph textboxPara = new Paragraph(_documentNode);

Run textboxParaRun = new Run(_documentNode);
textboxParaRun.Text = stepNumber;
textboxPara.AppendChild(textboxParaRun);
textbox.AppendChild(textboxPara);

parentPara.AppendChild(textbox);

Hi Sean,


Thanks for your inquiry. Yes, you need to insert a Paragraph inside text box Shape. Please also try executing the following example:

// Create a blank document.

Document doc = new Document();

// Create a new shape of type TextBox

Shape textBox = new Shape(doc, ShapeType.TextBox);

// Set some settings of the textbox itself.

// Set the wrap of the textbox to inline

textBox.WrapType = WrapType.None;

// Set the horizontal and vertical alignment of the text inside the shape.

textBox.HorizontalAlignment = HorizontalAlignment.Center;

textBox.VerticalAlignment = VerticalAlignment.Top;

// Set the textbox height and width.

textBox.Height = 50;

textBox.Width = 200;

// Set the textbox in front of other shapes with a lower ZOrder

textBox.ZOrder = 2;

// Let's create a new paragraph for the textbox manually and align it in the center. Make sure we add the new nodes to the textbox as well.

textBox.AppendChild(new Paragraph(doc));

Paragraph para = textBox.FirstParagraph;

para.ParagraphFormat.Alignment = ParagraphAlignment.Center;

// Add some text to the paragraph.

Run run = new Run(doc);

run.Text = "Content in textbox";

para.AppendChild(run);

// Append the textbox to the first paragraph in the body.

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

// Save the output

doc.Save(MyDir + @“out.docx”);


I hope, this helps.

Best regards,