I am trying to extract information about the positions and dimensions of text boxes in a Word document using Apache POI. Unlike Aspose.Words that provide methods and classes to handle text boxes and other shapes, Apache POI doesn’t seem to provide those functionalities. If there is a way to extract information about the position and dimensions of text boxes using Apache POI it would be helpful.
XWPFDocument document = new XWPFDocument(OPCPackage.open(fis));
List<XWPFParagraph> paragraphs = document.getParagraphs();
XmlObject[] textBoxObjects;
for(XWPFParagraph paragraph : paragraphs)
{
textBoxObjects = paragraph.getCTP().selectPath(
"declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' " +
"declare namespace wps='http://schemas.microsoft.com/office/word/2010/wordprocessingShape' " +
"declare namespace v='urn:schemas-microsoft-com:vml'"+ ".//*/wps:txbx/w:txbxContent | .//*/v:textbox/w:txbxContent");
//
for (int i =0; i < textBoxObjects.length; i++){
XWPFParagraph embeddedPara = null;
try {
XmlObject[] paraObjects = textBoxObjects[i].selectChildren(new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "p"));
for (int j=0; j<paraObjects.length; j++) {
embeddedPara = new XWPFParagraph(CTP.Factory.parse(paraObjects[j].xmlText()), paragraph.getBody());
System.out.println(embeddedPara.getText());
}
}
}
Using the above script I am extracting the text from text boxes, but I also need information about the position and dimensions of text boxes to proceed forward.
If there is a way to extract those information, it would be helpful.
Thanks in advance.