Hi Team,
We are facing issue when converting MSG file to (MHTML to ) PDF, text / table are cut off on right side but other msg files are being converted fine. To fix the issue, we tried below snippet but it doesn’t work.
Note - If the same msg file is being saved from some other outlook client, PDF conversion works fine so I am not sure if attached MSG file itself is corrupted / incompatible.
// auto fit tables to page
NodeCollection tables = doc.getChildNodes(NodeType.TABLE, true);
for (Table table : (Iterable<Table>) tables)
table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);
// Prevent embedded images from being cut off
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
for (com.aspose.words.Shape shape : (Iterable<Shape>) shapes) {
if (shape.getShapeType() == ShapeType.IMAGE) {
if (doc.getFirstSection().getPageSetup().getPageWidth() < shape.getWidth()) {
double scale = (doc.getFirstSection().getPageSetup().getPageWidth() - 140) /
shape.getWidth();
shape.setWidth(doc.getFirstSection().getPageSetup().getPageWidth() - 140);
shape.setHeight(shape.getHeight() * scale);
}
}
}
I have attached the respective msg & pdf file below.
Msg with converted PDF.zip (300.2 KB)
Please let me know if additional details are required. Thanks.