שמירת קובץ MSG כ‑PDF

המרת הודעת דוא"ל ל‑PDF

הקוד הבא מציג המרה של הודעת דוא"ל ל‑PDF באמצעות Aspose.Email בשילוב עם Aspose.Words for Java. פעולה זו כוללת את השלבים הבאים:

  1. טען את הודעת הדוא"ל באמצעות MailMessage
  2. שמור את הודעת הדוא"ל ל‑MemoryStream כ‑MHTML
  3. טען את הזרם באמצעות Aspose.Words
  4. שמור את ההודעה כ‑PDF

הודעת הדוא"ל המקורית נראית כך:

|todo:image_alt_text| | :- | |דמות: קובץ MSG מקור |

|todo:image_alt_text| | :- | |דמות: קובץ PDF מומר | Java

static void emailToPdf(String emailPath, String pdfPath) throws Exception {
    MailMessage eml = MailMessage.load(emailPath);

    // Save the message to an output stream in MHTML format
    ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
    eml.save(emlStream, SaveOptions.getDefaultMhtml());

    // Load the stream into a Word document; the Aspose.Words types are qualified
    // because com.aspose.email has a LoadOptions class of its own
    com.aspose.words.LoadOptions lo = new com.aspose.words.LoadOptions();
    lo.setLoadFormat(com.aspose.words.LoadFormat.MHTML);
    com.aspose.words.Document doc = new com.aspose.words.Document(
            new ByteArrayInputStream(emlStream.toByteArray()), lo);

    // Save to disk
    doc.save(pdfPath, com.aspose.words.SaveFormat.PDF);

    // or save to a stream
    ByteArrayOutputStream foStream = new ByteArrayOutputStream();
    doc.save(foStream, com.aspose.words.SaveFormat.PDF);
}