MSG 파일을 PDF로 저장

이메일 메시지를 PDF로 변환

다음 코드는 Aspose.Email과 Java용 Aspose.Words를 결합하여 이메일 메시지를 PDF로 변환하는 방법을 보여줍니다. 다음 단계가 포함됩니다:

  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);
}