Table Image split issue

Hi Aspose Team,

I have extracted the image from the document. I have extracted the image, but figures 1 and 2 are combined into a single figure.

Source code: Source_Code.zip (769 Bytes)

Input: Input.docx (109.5 KB)

Current Output : Fig0001.pdf (83.8 KB)

Excepted output: Excepted.zip (78.8 KB)

Thanks in advance

Regards
Mahi

@Mahesh39 You should process each column in your table to get the desired output. For example see the following code:

Document doc = new Document("C:\\Temp\\in.docx");
// Update list labels since captions in the document are list with FigX label.
doc.updateListLabels();

// Get the table.
Table table = doc.getFirstSection().getBody().getTables().get(0);

// Suppose each row in the table has the same number of cells.
for (int colIdx = 0; colIdx < table.getFirstRow().getCells().getCount(); colIdx++)
{

    // Suppose the last row contains a cation and the first row contains the shape.
    String caption = table.getLastRow().getCells().get(colIdx).toString(SaveFormat.TEXT).trim();

    System.out.println(caption);
    if (caption.startsWith("Fig"))
    {
        // Get the shape.
        Node image = table.getFirstRow().getCells().get(colIdx).getChild(NodeType.SHAPE, 0, true);

        if (image == null)
            continue;

        // Save the shape.
        Document tmp = (Document)doc.deepClone(false);
        tmp.ensureMinimum();

        Node dstImage = tmp.importNode(image, true, ImportFormatMode.USE_DESTINATION_STYLES);
        tmp.getFirstSection().getBody().getFirstParagraph().appendChild(dstImage);

        tmp.save("C:\\Temp\\" + caption + "_" + colIdx + ".pdf");
    }
}
1 Like