EML and MSG are popular email formats used by MS Outlook to store emails. There could be the cases when you need to share the content of EML or MSG files from within your web or desktop applications. One of the most suitable solutions is the conversion of email files to PDF format. In this article, you will learn how to convert emails to PDF in Java. You can use the provided code samples for EML to PDF and MSG to PDF conversion in C#.
Java Email to PDF Converter - Free Download
To convert EML or MSG emails to PDF, we will use the combination of Aspose.Email for Java and Aspose.Words for Java. The former is an email API that provides a bunch of features to create email client applications. Whereas, the latter one is a word processing API for creating and manipulating Word documents. You can use the following Maven configurations to install the API in your Java applications.
Repository:
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
<repository>
Dependencies:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-email</artifactId>
<version>22.2</version>
<classifier>jdk16</classifier>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>22.3</version>
<type>pom</type>
</dependency>
Also, you can download the JARs of the APIs from the following links.
Convert an EML or MSG to PDF in Java
The following are the steps to convert an EML or MSG email to PDF in Java.
- Load the email file using MailMessage class.
- Save the email message into a ByteArrayOutputStream object as default MHTML format.
- Create an instance of LoadOptions class and set the load format as MHTML.
- Instantiate Document class and pass ByteArrayOutputStream and LoadOptions objects as parameters to its constructor.
- Convert the email to PDF using Document.save(String, SaveFormat.PDF) method.
The following is the complete code to convert an email to PDF in Java.
Email to PDF Java Converter APIs - Get a Free License
You can get a free temporary license in order to try the APIs without evaluation limitations.
Email to PDF - Live Demo
Aspose EML to PDF Online Converter
The following is the Aspose’ online converter to convert EML files to PDF.
Aspose MSG to PDF Online Converter
You can use the following online converter for MSG to PDF demo.
Conclusion
In this article, you have learned how to convert EML or MSG emails to PDF in Java. We have demonstrated how to use the combination of Aspose.Email and Aspose.Words to implement email to PDF conversion from within Java applications. You can also explore the below-mentioned documentations of both of the APIs. Also, you can post your queries to our forum.