javaasposeaspose.words

How can i get total paragraph count in word document using Aspose.words library in java


I was trying with node collection but it is not giving exact count. i am looking for Table and cell count.

Document doc=new Document(filePath);
NodeCollection nodeCollection = doc.getChildNodes(NodeType.Paragraph,true);
int paraCount = nodeCollection.getCount();
System.out.println(paraCount);

Solution

  • Your code is correct and returns number of paragraphs in the whole document including paragraphs in header/footer, textboxes, footnotes etc. See Aspose.Words DOM for more information: https://docs.aspose.com/words/java/aspose-words-document-object-model/

    However, for example, if you use Aspose.Words in evaluation mode, the document might be truncated due to evaluation version limitations. In evaluation mode Aspose.Words limits the maximum document size to several hundreds of paragraphs. To test it whiteout limitations, you can request a free temporary 30-days license.