Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu May 09, 2024 6:14 pm

Hi Team


Please let me know how to add text within the shape(rectangle).


Thanks in advance

pr20080798
 
Posts: 159
Joined: Wed Jan 20, 2021 1:15 pm

Fri May 10, 2024 3:08 am

Hi,

Thank you for your message.
Please refer to code below:
Code: Select all
        String output = "output/shapenew.docx";
        Document doc = new Document();
        Section sec = doc.addSection();
        //add a new paragraph
        Paragraph para = sec.addParagraph();
        //add textbox
        TextBox txtBox = new TextBox(doc);
        txtBox.setShapeType(ShapeType.Rectangle);
        txtBox.setWidth(100);
        txtBox.setHeight(100);
        Paragraph paragraph = txtBox.getBody().addParagraph();
        paragraph.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
        paragraph.appendText("Start");
        txtBox.setHorizontalPosition(100);
        txtBox.setVerticalPosition(100);
        para.getChildObjects().add(txtBox);
        //save the document
        doc.saveToFile(output, FileFormat.Docx);


If there's still any issue, welcome to contact us again!

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 460
Joined: Mon Nov 07, 2022 8:10 am

Return to Spire.Doc

cron