0
votes

I found the answer that explains how to insert a new text box into docx document.

create text box in document .docx using apache poi

The problem is that I cannot change the font size inside a newly created text box.

Does anyone know how to do that?

1
As the linked answer already works on the underlying XML structure, you probably need to create such a document with Microsoft Word and then unzip the .docx file (it's a zip) and look at the xml-files to see where the text size is stored. Then you can use the lowlevel POI APIs to add that XML structure.centic

1 Answers

0
votes

Reference : create text box in document .docx using apache poi

The ctTxbxContent.addNewP() in my code creates a CTP object. The XWPFParagraph has a constructor XWPFParagraph(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP prgrph, IBody part). So you can get a XWPFParagraph from the CTP object and then use the default apache-poi methods further.

...
  CTTxbxContent ctTxbxContent = ctShape.addNewTextbox().addNewTxbxContent();
  XWPFParagraph textboxparagraph = new XWPFParagraph(ctTxbxContent.addNewP(), (IBody)doc);
  XWPFRun textboxrun = textboxparagraph.createRun();
  textboxrun.setText("The TextBox text...");
  textboxrun.setFontSize(24);
...