How to Convert Outlook Email to PDF using Java

In this simple tutorial, we will focus on how to convert Outlook Email to PDF using Java along with detailed steps to configure the environment. You will observe that in order to convert MSG to PDF Java based API can be used. Moreover, this application can be used in any of the commonly available operating systems like Windows, macOS, or Linux.

Steps to Convert Outlook Email to PDF using Java

  1. Install Aspose.Email and Aspose.Words JAR file from Maven repository
  2. Instantiate the MailMessage class object to load the EML or MSG email file from the disk
  3. Convert the loaded Email (MSG/EML) file as a ByteArrayOutputStream to an intermediate MHTML format
  4. Instantiate the Document class object to load the intermediate MHTML file from stream by setting the LoadFormat to MHTML
  5. Save the loaded MHTML to PDF using the save method

By following the aforementioned steps in Java MSG to PDF converter application is developed, whereby the process starts by loading the EML or MSG file from the disk using the MailMessage class object and then converted to an intermediate stream in an MHTML format using the save method. We will then load the intermediate MHTML using the Document class object and for converting EML to PDF Java based save method will be used.

Code to Convert Outlook Email to PDF using Java

In order to convert EML to PDF Java based API is used with the help of simple API calls. The above example is useful for loading and converting both MSG and EML files format. The output PDF can be customized by setting properties like Compliance, ColorMode, ImageCompression and JpegQuality.

To convert MSG to PDF Java based API is explored in this article. If you are looking for how to convert EML to MSG using Java, refer to the article on how to convert EML to MSG using Java.

 English