After working with sample code and source file provided by you, it seems to be an issue related to Aspose.Email while truncating the right side image when saving to MHTML. A ticket with ID EMAILJAVA-34784 has bee created to further investigate and resolve the issue.
You have shared MSG file where as you are using EmlLoadOptions(). You need to use MsgLoadOptions() for MSG file. Is this the case with you in another thread where you have reported InvalidOperation Exception issue?
Thanks for update. We are reading the outlook and process the eml file for conversion.
If I used below code than it’s correct right? mailMsg = MailMessage.load(docInputStream, new EmlLoadOptions());
I have the eml file that causing the InvalidOperarion exception issue. If you want, I can share with you.docset_pvai_10378803.zip (34.4 KB)
There is no InvalidOperarion exception issue with the new file shared by you as well on our end. I have shared the output and used sample code with you for this in another thread as well where you have shared the same thing.
I regret to share that at present the issue is still unresolved and we request for your patience. We will share the good news with you as soon as the issue will be addressed.
From Aspose.Email perspective, this issue is not reproduced as API produced the same output as MS Outlook. If you can try the solution mentioned in following link for your convenience.
// make inline image resize @SuppressWarnings(“rawtypes”)
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
int imageIndex = 0;
for (Shape shape : (Iterable) shapes)
{
if (shape.hasImage())
{
LOG.error("shape image "+shape);
// Calculate the free space based on an inline or floating image. If inline we must take the page margins into account.
PageSetup ps = shape.getParentParagraph().getParentSection().getPageSetup();
double freePageWidth = shape.isInline() ? ps.getPageWidth() - ps.getLeftMargin() - ps.getRightMargin() : ps.getPageWidth();
double freePageHeight = shape.isInline() ? ps.getPageHeight() - ps.getTopMargin() - ps.getBottomMargin() : ps.getPageHeight();
I have manually converted “FW_ Issue 704.msg” to MHT format by using MS Outlook 2019 and then converted this MHT to PDF format by using MS Word 2019 and attached the final PDF file here for your reference (see msw-2019.pdf (240.6 KB)). You can observe the same undesired behavior of image in MS Word’s generated PDF file. So, this is the expected behavior as Aspose.Words mimics the behavior of MS Word in this case.
But, you can workaround this issue by using the following code:
Document doc = new Document("C:\\Temp\\Aspose.Email generated.mht");
for (Shape shape : (Iterable<Shape>) doc.getChildNodes(NodeType.SHAPE, true)) {
shape.setLeft(-55);
resizeLargeImage(shape);
}
doc.save("C:\\Temp\\awjava-21.6.pdf");
public static void resizeLargeImage(Shape image) throws Exception {
// Return if this shape is not an image.
if (!image.hasImage())
return;
// Calculate the free space based on an inline or floating image. If inline we must take the page margins into account.
PageSetup ps = image.getParentParagraph().getParentSection().getPageSetup();
double freePageWidth = image.isInline() ? ps.getPageWidth() - ps.getLeftMargin() - ps.getRightMargin() : ps.getPageWidth();
double freePageHeight = image.isInline() ? ps.getPageHeight() - ps.getTopMargin() - ps.getBottomMargin() : ps.getPageHeight();
// Is one of the sides of this image too big for the page?
ImageSize size = image.getImageData().getImageSize();
boolean exceedsMaxPageSize = size.getWidthPoints() > freePageWidth || size.getHeightPoints() > freePageHeight;
if (exceedsMaxPageSize) {
// Calculate the ratio to fit the page size based on which side is longer.
boolean widthLonger = (size.getWidthPoints() > size.getHeightPoints());
double ratio = widthLonger ? freePageWidth / size.getWidthPoints() : freePageHeight / size.getHeightPoints();
// Set the new size.
image.setWidth(size.getWidthPoints() * ratio);
image.setHeight(size.getHeightPoints() * ratio);
}
}