How to find image counts

Dear team,

we are extracting images from documents using aspose, here we are finding total images counts from docx, and we are using below mentioned source code for find image count but below document we are not able to find figure count

try
{
    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))
        {
            if (!(para.toString(SaveFormat.TEXT).trim().startsWith("Figure 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);
                    }
                }
                catch (NullPointerException e)
                {
                    logger.info("Exception ", e.getMessage());
                    e.printStackTrace();
                }
            }
        }
    }
    initDoc.save(interim);
}
catch (Exception e)
{
    logger.info("Exception ", e.getMessage());
    e.printStackTrace();
}

input document : Manuscript-clean.docx (3.1 MB)

please do needful

@e503824 The problem occurs because in your condition you do not check next and previous sibling paragraph for null. In your document image caption is in table cell and is the only paragraph in cell, so it does not have neither next nor previous siblings. Modify your condition line this:

Table parentTable = (Table)para.getAncestor(NodeType.TABLE);
Paragraph nextPara = (Paragraph)para.getNextSibling();
Paragraph prevPara = (Paragraph)para.getPreviousSibling();
if ((nextPara != null && nextPara.getChildNodes(NodeType.SHAPE, true).getCount() > 0)
        || (prevPara != null && prevPara.getChildNodes(NodeType.SHAPE, true).getCount() > 0)
        || (parentTable != null && parentTable.getChildNodes(NodeType.SHAPE, true).getCount() > 0))
{
    // your code here
}

Dear Team,

I have tried but it is not working for me

@e503824 Here is fool code I used for testing:

String FIG = "Fig";
String SCHEME = "Scheme";
String PLATE = "Plate";

Document initDoc = new Document("C:\\Temp\\in.docx");
try
{
    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))
        {
            if (!(para.toString(SaveFormat.TEXT).trim().startsWith("Figure Captions")))
            {
                try
                {
                    Table parentTable = (Table)para.getAncestor(NodeType.TABLE);
                    Paragraph nextPara = (Paragraph)para.getNextSibling();
                    Paragraph prevPara = (Paragraph)para.getPreviousSibling();
                    if ((nextPara != null && nextPara.getChildNodes(NodeType.SHAPE, true).getCount() > 0)
                            || (prevPara != null && prevPara.getChildNodes(NodeType.SHAPE, true).getCount() > 0)
                            || (parentTable != null && parentTable.getChildNodes(NodeType.SHAPE, true).getCount() > 0))
                    {
                        String allFignames = para.toString(SaveFormat.TEXT).trim();
                        System.out.println(allFignames);
                    }
                }
                catch (NullPointerException e)
                {
                    System.out.println("Exception " + e.getMessage());
                    e.printStackTrace();
                }
            }
        }
    }
}
catch (Exception e)
{
    System.out.println("Exception " + e.getMessage());
    e.printStackTrace();
}

It prints the following output:

Figure 1. Schematic diagrams for the two-step modification approach used in this study. (a) Modification of 3D FAPbI3 perovskite film with propionic acid (PA). (b) Dimensional engineering of FAPbI3 with 2D FPEAI ammonium salt to fabricate mixed 3D/2D heterostructure and used nitrosonium tetrafluoroborate (NOBF4) modifier as a p-type dopant into FPEAI precursor solution. The Figure also shows the chemical structures of FAPbI3, propionic acid, FPEAI, and NOBF4 materials.
Figure 2. (a) UV–vis absorption spectra, (b) steady-state photoluminescence (PL) of different perovskite films on glass substrate. (c) XRD patterns of different perovskite layer types on the FTO/c-TiO2/mp-TiO2 substrates. (d) The extracted tauc curves of perovskite layers from the plotted UV-vis spectra in (a). (e) The curve of full width at half maximum (FWHM) for different perovskite layer types, FWHM values were obtained from fitting the presented PL spectra in (b). Zoomed XRD patterns of different perovskite layers around 2θ=14 o. The pure three-dimensional (3D) perovskite film, the modified 3D perovskite film with propionic acid (PA), the pristine 3D/2D mixed-dimensional perovskite film, and the modified 3D/2D hybrid perovskite layer with nitrosonium tetrafluoroborate (NOBF4) dopant were labeled as control 3D, modified 3D, control 3D/2D, and modified 3D/2D, respectively.
Figure 3. Top-view FE-SEM image of the (a) pure three-dimensional (3D) perovskite layer (control 3D), (b) modified 3D perovskite layer with propionic acid (PA), (c) pristine 3D/2D mixed-dimensional perovskite layer, and (d) the modified 3D/2D mixed-dimensional perovskite layer with nitrosonium tetrafluoroborate (NOBF4) dopant (modified 3D/2D). (e-h) Grain size distribution of different perovskite layers obtained from FE-SEM images. Cross-sectional FE-SEM images of the (i) Control 3D and (j) the modified 3D/2D perovskite films. AFM images of the (k) control 3D and (l) modified 3D/2D perovskite films. To record FE-SEM and AFM images, perovskite layers were coated on mp-TiO2 substrates. The scale bars of top-view and cross-sectional FE-SEM images are 500 nm.
Figure 4. (a) Schematics of the mixed-dimensional perovskite solar cell (PSC) used here. The statistical distribution of power conversion efficiency (PCE) of the (b) three-dimensional (3D) PSCs without and with different amounts of propionic acid (PA) in the perovskite precursor. (c) The statistical PCE distribution of the mixed-dimensional 3D/2D perovskite layers without and with different amounts of nitrosonium tetrafluoroborate (NOBF4) dopant in the 2D cation precursor. (d) The current density–voltage (J–V) curves of the best-performing PSC devices based on the control 3D, modified 3D, control 3D/2D, and the modified 3D/2D hybrid perovskite films. (e) Incident photon-to-current efficiency (IPCE) responses of PSCs and their integrated current densities. (f) J-V curves of the control 3D and modified 3D/2D PSCs with both reverse and forward voltage scan directions to study hysteresis phenomena.
Figure 5. (a) The curve of open-circuit voltage (VOC) versus the intensity of light for different perovskite solar cells (PSCs). (b) The dark current-voltage (I-V) characteristics of the hole-only device with a structure of FTO/PEDOT:PSS/Perovskite layer/HTL/Au to measure hole mobility. (c) Electrical impedance spectroscopy (EIS) spectra of different PSCs at VOC under dark conditions. (d) Mott-Schottky responses of PSC devices based on different perovskite layers. (e) Time-resolved photoluminescence (TRPL) of perovskite films deposited on glass to monitor carriers lifetime in the perovskite layer. (f) steady-state photoluminescence (PL) of PSCs based on different perovskite layers.
Figure 6. (a) Power conversion efficiency (PCE) degradation tracking of the unencapsulated solar cell devices based on control 3D and modified 3D/2D perovskite layers in ambient air with relative humidity (RH) of 25-40% at room temperature in dark condition. (b) The results of damp-heat stability test of the unencapsulated perovskite solar cell devices at 85 oC under 85% RH in a dark chamber. Water contact angle measurements of the (c) control 3D and (d) modified 3D/2D perovskite films. (e) The long-term operational stability of the control 3D and modified 3D/2D PSCs under full solar illumination (100 mW/cm2) in an inert nitrogen atmosphere without any temperature control during the test.

Which is expected