Paragraph inside shape

Hi Aspose Team,

I’ve tried to mimic following fragment of html (VML) code in word using your library:

<v:shape
    coordsize="200 200"
    strokecolor="red" fillcolor="red"
    style="top:10pt;left:10pt;width:50pt;height:50pt">
    <v:textbox 
        inset="10px, 10px, 10px, 10px">
	VML
   </v:textbox>
</v:shape>

Basically, I’d like to have an Textbox with some text inside other shape. Please check the code bellow for replication. All works fine up to the moment where I’m adding text to the textbox shape (two commented lines of code). When you uncomment them - document is created, but displays an error when opened in Word (2016):

public void Test()
        {
            var doc = new Document();
            var body = new Body(doc);
            var section = new Section(doc);
            doc.AppendChild(section);
            section.AppendChild(body);
            var para = new Paragraph(doc);
            var shape = new Shape(doc, ShapeType.Rectangle)
            {
                CoordSize = new Size(1000, 1000),
                StrokeColor = Color.Black,
                FillColor = Color.Aqua
            };
            var shape2 = new Shape(doc, ShapeType.TextBox)
            {
                CoordSize = new Size(1000, 1000),
                StrokeColor = Color.Black,
                FillColor = Color.Aqua
            };
            para.AppendChild(shape);
            var para2 = new Paragraph(doc);
            var para3 = new Paragraph(doc);
            para2.AppendChild(shape2);
            shape.AppendChild(para2);
            //shape2.AppendChild(para3);
            //para3.AppendChild(new Run(doc, "test"));
            body.AppendChild(para);
            doc.Save("TestNewDoc.docx");
        }

Could you please take a look what’s causing this behavior and, if possible, give me some clues how to achieve the results described at the beginning?

Thanks,
Mateusz

@acturisaspose,

Thanks for your inquiry. Please use the following code example to get the desired output. Hope this helps you.

var doc = new Document();
doc.RemoveAllChildren();
var body = new Body(doc);
var section = new Section(doc);
doc.AppendChild(section);
section.AppendChild(body);

var para = new Paragraph(doc);
var shape = new Shape(doc, ShapeType.Rectangle)
{
    CoordSize = new Size(1000, 1000),
    StrokeColor = Color.Black,
    FillColor = Color.Aqua,
    Width = 100,
    Height = 100
};
                 
para.AppendChild(shape);

var para2 = new Paragraph(doc);
shape.AppendChild(para2);

para2.AppendChild(new Run(doc, "test"));

body.AppendChild(para);

doc.Save(MyDir + "18.7.docx");

Hi Tahir,

many thanks for your code example - but this is not covering my case. Code as you’ve posted here works fine - the problem occurs when I add another Image inside para2 from your case
Image2 = new Shape(documentBuilder.Document, ShapeType.TextBox); para2.AppendChild(Image2);

and add some text to the 2nd Image.
Could you please investigate once again with the additional details?

Many thanks in advance,
Mateusz

@acturisaspose,

Thanks for your inquiry. Please ZIP and attach your expected output Word document here for our reference. We will then provide you more information about your query along with code example.