Hi Team,
We are facing issues while trying to convert a .msg to .pdf
The error is thrown at words.Document instantiation.
We are using aspose-words:21.10:jdk17 and aspose-email:22.5:jdk16
Here is the running code -
public static byte[] convertEmailToPdf(ByteArrayInputStream emailInputStream) throws Exception {
ByteArrayOutputStream result = new ByteArrayOutputStream();
try {
MailMessage mailMsg = MailMessage.load(emailInputStream);
// converting mailMsg to HTML (aspose doesn't support direct eml -> pdf conversion)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mailMsg.save(baos, SaveOptions.getDefaultMhtml());
// loading HTML into Aspose.Words Document
LoadOptions lo = new LoadOptions();
lo.setLoadFormat(LoadFormat.MHTML);
Document document = new Document(new ByteArrayInputStream(baos.toByteArray()), lo);
// finally saving Document as PDF.
document.save(result, SaveFormat.PDF);
return result.toByteArray();
} catch (Exception ex) {
LOGGER.error("Exception occurred while converting Email to pdf :" + ex.getMessage());
throw ex;
} finally {
result.close();
}
}
Attaching sample .msg file in ZIP sample.zip (566.0 KB)