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

Free Support Forum - aspose.com

TextBox Shape with Rich Text Format content


I try to add to document a textbox with rich text format,

For instance,

With this code, we can add normal (standard) text:

Aspose.Words.Paragraph par = new Aspose.Words.Paragraph(doc);

par.AppendChild(new Run(doc, "HELLO"));


But this is not valid if text is on rich text format. With a Word Object will be...

Word.Shape shape = WordApp.ActiveDocument.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 100, 100, 100, 100, ref missing);

shape.RTF = richTextBox1.Rtf;

How can i do this with Aspose?



<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. There is no direct way to achieve this using Aspose.Words. However, you can use the same technique as described here to insert RTF:

Hope this helps.

Best regards.

Hi Alexey,

Into the link you just post me up, said:

//Insert rtd document into destination document<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

InsertDocument(insertAfterparentParagraph, rtfDoc);

Insert document method you can find here.


This link with method InsertDocument is broken. Please, can you post me this method? It is helpfull for me.

Thanks very much!!!

I just found here!, thanks!!


Hi again,

How can i insert a RTF document into a TextBox?.

I did this but not works, report me errors with Node InsertAfterNode parameter of InsertDocument method:

doc --> is the main document and will contains the textbox
rtfDoc --> is the rtfDoc with textbox content on RTF format.
textbox --> is the TextBox object.

How can i fill the InsertAfterNode parameter? (because textbox.FirstParagraph.FirstChild not works).
I know that is a node of TextBox but, what?

InsertDocument(?????, rtfDoc);

PD.- TextBox is empty, has no paragrahs, i have created it only with this clause...

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



<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You should just add one empty paragraph into the TextBox, then insert a document after this paragraph and then just remove this paragraph. Your code should look like the following:

// Create or open document.

Document doc = new Document();

// Open RTF document (or other document), which should be inserted into a textbox.

Document src = new Document(@"Test001\in.doc");

// Create textbox shape.

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

textbox.Width = 300;

textbox.Height = 300;

// Insert one empty paragraph into the textbox.

textbox.AppendChild(new Paragraph(doc));

// Insert our source document after the first paragraph in the textbox.

InsertDocument(textbox.FirstParagraph, src);

// Remove the first empty paragraph from the textbox.


// Insert textbox into the document.



Hope this helps.

Best regards.

I just found a possible solution.
I need create a new paragraph with string empty. Now i can reference to textbox.FirstChild node on InsertDocument parameter.
Here you are the code snippet:

Paragraph par = new Paragraph(doc);
par.AppendChild(new Run(doc, string.Empty));
InsertDocument(textbox.FirstChild as Paragraph, rtfDoc);

If you know a better solution, please tell me.
Thanks for your pattience!

Best regards!.

Alexey, we post the solution at the same time!! ;-)

Thanks very much!!!