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

Free Support Forum - aspose.com

Need to find all image count

Dear team,

we are using aspose java for image extraction, now we need to get all images name , but few cases we are not able get proper result and we are using below source code for find images

for (Paragraph para : (Iterable<Paragraph>) initDoc.getChildNodes(NodeType.PARAGRAPH, true)) {
		if ((para.getText().trim().startsWith(FIG) || para.getText().trim().startsWith(SCHEME)
		|| para.getText().trim().startsWith(PLATE)) && !AIE.supplymentryCheck(para.toString(SaveFormat.TEXT).trim())) {
		if (!(para.toString(SaveFormat.TEXT).trim().startsWith("Figure Captions")) 
			&& (!(para.toString(SaveFormat.TEXT).trim().startsWith("Figures and captions")))) {
					try {
						Table parentTable = (Table)para.getAncestor(NodeType.TABLE);
						if((((Paragraph) para.getNextSibling()).getChildNodes(NodeType.SHAPE, true).getCount() > 0) 
								||(((Paragraph) para.getPreviousSibling()).getChildNodes(NodeType.SHAPE, true).getCount() > 0) 
								&& parentTable!=null && parentTable.getChildNodes(NodeType.SHAPE, true).getCount()>0)
				
								{
							String allFignames = null;
							{
								allFignames = formatImgcaption(para.toString(SaveFormat.TEXT).trim(), nameAppend);
								
							}
							allimages.add(allFignames);

input : Manuscript-4.7_Interim.docx (7.1 MB)

please do needful

@e503824 In your document part of figures are placed in table, while their captions are outside the tables. So you should modify your condition like this:

Table parentTable = (Table)para.getAncestor(NodeType.TABLE);
CompositeNode nextNode = (CompositeNode)para.getNextSibling();
CompositeNode prevNode = (CompositeNode)para.getPreviousSibling();
if ((nextNode != null && nextNode.getChildNodes(NodeType.SHAPE, true).getCount() > 0)
        || (prevNode != null && prevNode.getChildNodes(NodeType.SHAPE, true).getCount() > 0)
        || (parentTable != null && parentTable.getChildNodes(NodeType.SHAPE, true).getCount() > 0))
{
    System.out.println(para.toString(SaveFormat.TEXT).trim());
}