Lưu tin nhắn email thành PDF
Contents
[
Hide
]
Aspose.Email - Lưu tin nhắn email dưới dạng PDF
Đoạn mã dưới đây cho thấy cách chuyển tin email sang PDF bằng Aspose.Email kết hợp với Aspose.Words cho Java. Điều này bao gồm các bước sau:
- Tải tin email bằng MailMessage
- Lưu tin email vào MemoryStream dưới dạng MHTML
- Tải luồng bằng Aspose.Words
- Lưu tin dưới dạng 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);
Tải mã đang chạy
Tải mã mẫu
Để biết thêm chi tiết, truy cập Lưu file MSG dưới dạng PDF.