Insert an Image inside a TextBox

Is this possible? I can’t seem to get this to work at all. I want to create a TextBox which contains an image and a caption paragraph, and that autosizes to fit the image. Is this feasible currently?

Hello

Thanks for your inquiry. You can try using the code like the following to achieve what you need:

Image img = Image.FromFile("Test.jpg");
// Get width and height of the image in points.
double width = ConvertUtil.PixelToPoint(img.Width, img.HorizontalResolution);
double height = ConvertUtil.PixelToPoint(img.Height, img.VerticalResolution);
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create textbox shape.
Shape textbox = new Shape(doc, ShapeType.TextBox);
textbox.TextBox.FitShapeToText = true;
textbox.Width = width + textbox.TextBox.InternalMarginLeft + textbox.TextBox.InternalMarginRight;;
textbox.Height = height + textbox.TextBox.InternalMarginTop + textbox.TextBox.InternalMarginBottom;
// Insert one empty paragraph into the textbox.
textbox.AppendChild(new Paragraph(doc));
// Insert text box into the document.
builder.InsertNode(textbox);
// Move documentBuilder cursot to the paragraph inside the textbox.
builder.MoveTo(textbox.FirstParagraph);
// Insert image
builder.InsertImage(img);
builder.InsertParagraph();
// Insert some text.
builder.Write("This is text inside textbox");
builder.Write("This is text inside textbox");
doc.Save("out.docx");

Hope this helps.
Best regards,

Thanks, that works great.