Dear support-Team,
we are using Aspose Words for Java, and we have HTML as input with a table.
The table has 2 columns and one of these columns has a fixed width of 50%.
Inserting an image into the column which is wider than the column leads to the image being inserted scaled down such that it can fit into the column with 50% width.
When we insert the HTML in Aspose, in the resulting docx, the image is not scaled down. Instead, the column has become larger than the configured 50%.
The table in HTML:
table-with-picture-in-cell-html.png (372 Bytes)
The table in Word:
table-with-picture-in-cell-docx.png (484 Bytes)
Please use this code to reproduce (the src-attribute to the image needs to point to a suitable image file that is larger than the column):
public class AsposeTest {
public static void main(String[] args) {
try {
File file = File.createTempFile("tempFile",".docx");
FileOutputStream openOutputStream = FileUtils.openOutputStream(file);
DocumentBuilder documentBuilder = new DocumentBuilder();
documentBuilder.insertHtml("<table style=\"border-collapse: collapse; border: 1px solid black;\" border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\"><tbody><tr><td> </td><td style=\"width: 50%;\"><img src=\"...\"></td></tr></tbody></table>");
documentBuilder.getDocument().save(openOutputStream, new OoxmlSaveOptions());
} catch (Exception e) {
e.printStackTrace();
}
}
}
The problem can be reproduced in the most recent version of Aspose Words for Java 21.4.
Thanks for your support