We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Duplicated paragraph nodes are returned by Document.getChildNodes using Java

Hi,

I want to count paragraphs with this code (JAVA) :

int nParagraph=0;
com.aspose.words.NodeCollection children = doc.getChildNodes(com.aspose.words.NodeType.PARAGRAPH, true);
for (com.aspose.words.Paragraph paragraph : (Iterable<com.aspose.words.Paragraph>) children) {
if (!StringUtils.isEmpty(paragraph.getText())) {
System.out.println(":::::PARAGRAPH:::::"+paragraph.getText());
nParagraph++;
}
}
System.out.println(":::::COUNT PARAGRAPH:::::"+nParagraph);
System.out.println(":::::COUNT PARAGRAPH:::::"+doc.getChildNodes(com.aspose.words.NodeType.PARAGRAPH, true).getCount());

And the results are not equal to MS-Word. I found that because it include empty paragraphs, I handled this issue by filter empty paragraphs out, and there are duplicated paragraphs as attached pictures.
Is there a way to fix the duplicated paragraph? Please advise.

Regards

Screenshot from 2020-08-14 16-43-31.png (23.5 KB)
Screenshot from 2020-08-14 17-14-59.png (50.2 KB)
sample.zip (136.6 KB)

@rcomniscien

While using latest version of Aspose.Words for Java 20.8, we have not found the duplicate paragraph issue. Could you please share some more detail about your query? We will then provide you more information on it.

Sorry for late reply, I switch to other project. My project using Aspose.words 19.6. I tried to use version 20.8 but the result is same.

@rcomniscien

Please make sure that you are using the same document and code example. Could you please share the screenshot of input document (paragraph) that is duplicated by Aspose.Words? We will investigate this issue further and provide you more information on it.