Fit image in table cell

Hi, I am trying to fit image into cell, so its height and width doesn’t overlap cell border. Is there any solution?

@afasianok You can use LayoutCollector and LayoutEnumerator to calculate actual cell bounds and then use actual cell size to adjust image size:

Document doc = new Document("C:\\Temp\\in.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

// Get cells
Iterable<Cell> cells = doc.getChildNodes(NodeType.CELL, true);
for (Cell cell : cells)
{
    // Move enumerator to cell
    enumerator.setCurrent(collector.getEntity(cell.getFirstParagraph()));
    while (enumerator.getType() != LayoutEntityType.CELL)
        enumerator.moveParent();

    // Get bounding box of the cell
    Rectangle2D rect = enumerator.getRectangle();
    System.out.println("Page: " + enumerator.getPageIndex() + "\tX=" + rect.getX() + "; Y=" + rect.getY() + "; Width=" + rect.getWidth() + "; Height=" + rect.getHeight());
}