Convert MSG to PDF: missing some details
Used: Aspose Email + Aspose Words (latest version - java edition)
The crosses are missing in the PDF representation. Also missing in MHTML intermediate format.
Results: see uploaded files
Sample code:
public static void main( String[] args ) throws Exception {
try ( InputStream fis = new FileInputStream( "Sample.msg" ) ) {
MailMessage eml = MailMessage.load( fis );
// save to MHTML
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MhtSaveOptions so = SaveOptions.getDefaultMhtml();
eml.save( baos, so );
// load MHTML to word
LoadOptions lo = new LoadOptions();
lo.setLoadFormat(LoadFormat.MHTML);
Document doc = new Document( new ByteArrayInputStream( baos.toByteArray() ), lo );
doc.save("sample.pdf", SaveFormat.PDF);
}
}
The content in the original message is saved in RTF format. Aspose.Email does not fully support RTF format.
You can use Aspose.Words to convert RTF:
public final void test() throws Exception {
MapiMessage msg = MapiMessage.load("Sample.msg");
String rtf = msg.getBodyRtf();
if (rtf != null && !rtf.isEmpty()) {
// convert from RTF to HTML
String html = rtfToHtml(rtf);
msg.setBodyContent(html, BodyContentType.Html);
}
// save to MHTML
ByteArrayOutputStream os = new ByteArrayOutputStream();
msg.save(os, SaveOptions.getDefaultMhtml());
//msg.save("Sample.mhtml", SaveOptions.getDefaultMhtml());
// load MHTML to word
com.aspose.words.LoadOptions lo = new com.aspose.words.LoadOptions();
lo.setLoadFormat(com.aspose.words.LoadFormat.MHTML);
// save to PDF
com.aspose.words.Document doc = new com.aspose.words.Document(new ByteArrayInputStream(os.toByteArray()), lo);
doc.save("Sample.pdf", com.aspose.words.SaveFormat.PDF);
}
private String rtfToHtml(String rtf) throws Exception {
com.aspose.words.Document rtfDoc =
new com.aspose.words.Document(new ByteArrayInputStream(rtf.getBytes()), new com.aspose.words.RtfLoadOptions());
ByteArrayOutputStream os = new ByteArrayOutputStream();
com.aspose.words.HtmlFixedSaveOptions so = new com.aspose.words.HtmlFixedSaveOptions();
so.setExportEmbeddedCss(true);
so.setExportEmbeddedFonts(true);
so.setExportEmbeddedImages(true);
rtfDoc.save(os, so);
return os.toString();
}
In this case, the message is converted to MHTML format as expected. Sample.mhtml screen (18.6 KB)
When using Aspose.Words, RTF Shapes are correctly converted to HTML.
But further conversion to PDF gives the wrong result. You can refer to Aspose.Words for this issue.