Saving A MSG as PDF

Convert Email message to PDF

The following code shows converting email message to PDF using Aspose.Email in combination with Aspose.Words for Java. This involves the following steps:

  1. Load the email message using MailMessage
  2. Save the email message to MemoryStream as MHTML
  3. Load the stream using Aspose.Words
  4. Save the message as PDF

The source email message can be seen as follow:

Figure: Source MSG File
Figure: Converted PDF File

 static void EmailToPdf(String emailPath) throws Exception


       FileInputStream fstream=new FileInputStream(emailPath);

       MailMessage eml = MailMessage.load(fstream);

       //Save the Message to output stream in MHTML format

       ByteArrayOutputStream emlStream = new ByteArrayOutputStream();, SaveOptions.getDefaultMhtml());

       //Load the stream in Word document

       LoadOptions lo = new LoadOptions();


       Document doc = new Document(new ByteArrayInputStream(emlStream.toByteArray()), lo);

       //Save to disc"About Aspose.Pdf", SaveFormat.PDF);

       //or Save to stream

       ByteArrayOutputStream foStream = new ByteArrayOutputStream();, SaveFormat.PDF);