将电子邮件保存为 PDF
Contents
[
Hide
]
Aspose.Email - 将电子邮件保存为 PDF
以下代码演示了使用 Aspose.Email 与 Aspose.Words for Java 结合将电子邮件转换为 PDF。涉及以下步骤:
- 使用 MailMessage 加载电子邮件
- 将电子邮件保存为 MemoryStream 且格式为 MHTML
- 使用 Aspose.Words 加载流
- 将消息保存为 PDF
Java
FileInputStream fstream = new FileInputStream(dataDir + "message.msg");
MailMessage eml = MailMessage.load(fstream);
// Save the Message to output stream in MHTML format
ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
eml.save(emlStream, SaveOptions.getDefaultMhtml());
// Load the stream in Word document
LoadOptions lo = new LoadOptions();
lo.setLoadFormat(LoadFormat.MHTML);
Document doc = new Document(new ByteArrayInputStream(
emlStream.toByteArray()), lo);
// Save to disc
doc.save(dataDir + "About Aspose.Pdf", SaveFormat.PDF);
// or Save to stream
ByteArrayOutputStream foStream = new ByteArrayOutputStream();
doc.save(foStream, SaveFormat.PDF);
下载运行代码
下载示例代码
欲了解更多细节,请访问 将 MSG 保存为 PDF.