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

Free Support Forum - aspose.com

ArrayList within a Textbox

What’s the best way to create a Textbox, insert an ArrayList within this Textbox, and then place the Textbox within a Word document?

Hi

Thanks for your request. First of all you should create TextBox, then insert needed content inside this TextBox and then add this textbox to the document. Your code should look like the following:

// Create or open document.

Document doc = new Document();

// Create textbox shape.

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

textbox.Width = 300;

textbox.Height = 300;

Paragraph paragraph = new Paragraph(doc);

paragraph.AppendChild(new Run(doc, "Test"));

// Insert paragraph into the textbox.

textbox.AppendChild(paragraph);

// Insert textbox into the document.

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

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

Hope this helps.

Best regards.

Thanks so much for such a quick response! This example inserts Text...but how would I insert an ArrayList (such as an Image that I've pulled from another document)?

Thanks!

Hi

Thanks for your request. DocumentBuilder is a powerful class that is associated with a Document and allows dynamic document building from scratch or the addition of new elements to anexisting document. It provides methods to insert text, paragraphs, lists, tables, images and other contents, specification of font, paragraph, and section formatting, and other things. Using DocumentBuilder is somewhat similar in concept to using the StringBuilder class of the .NET Framework.

Please follow the link to learn how to insert elements into the document using DocumentBuilder:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/inserting-document-elements.html

Best regards,

Yes, I've looked at this; but it doesn't seem like there's a way to insert an Image into a Textbox unless it's pulling in an Image file. My Image is represented by an ArrayList (because I'm pulling that from another Word Doc).

Would you have an example of how to insert an ArrayList into a TextBox into a Doc?

Thanks for your time.

Hello

Thanks for your inquiry. In this case please try using the following code:

// Create or open document.

Document doc = new Document();

// Create DocumentBuidler object, it will help use to insert Image.

DocumentBuilder builder = new DocumentBuilder(doc);

// Create textbox shape.

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

textbox.Width = 300;

textbox.Height = 300;

Paragraph paragraph = new Paragraph(doc);

// Insert paragraph into the textbox.

textbox.AppendChild(paragraph);

// Insert textbox into the document.

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

// Move DocumentBuilder cursor to the first child of TextBox (newly created paragraph).

builder.MoveTo(textbox.FirstChild);

// Get image from ArreyList and insert

builder.InsertImage(imageBytes);

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

Best regards,