Free Support Forum -

Exporting EML to PDF

Hi, it appears that aspose.word will happily read an eml document and convert it to PDF. Two questions but:

1. Is that supported ?

2. How can I adjust the page size and margins of the PDF document that it produces ?



Thanks for your inquiry.

No, you can’t convert an EML file to PDF directly using Aspose.Words. However, you can use Aspose.Email in combination with Aspose.Words for converting EML to PDF. Please have a look at the code below for your kind reference, which reads an EML file, converts it to MHTML format, and then uses Aspose.Words to convert it to PDF.


//Load the EML file

var message = MailMessage.Load("Sample Eml File.eml", MessageFormat.Eml);

using (var mhtStream = new MemoryStream())


//Save the message as MHtml in memory stream

message.Save(mhtStream, MailMessageSaveType.MHtmlFromat);

//Create a new document

doc = new Aspose.Words.Document(mhtStream);

doc.Save("Output.pdf", Aspose.Words.SaveFormat.Pdf);


Secondly, you can adjust PDF document size using Aspose.Pdf. As your query involves multiple components, I am moving your thread to Aspose.Total forum where you will be guided appropriately.

Best regards,

Hi, Thanks for the reply.

The really interesting thing is that every test eml I pass to aspose.word works. I am not sure why I would want to add the complexity of converting to mhtml for no obvious reason.


Thanks for your inquiry. Could you please attach your sample EML file here for testing? I will investigate your scenario on my side and provide you more information.

Best regards,

Here are some examples


Thanks for the additional information. Although your files do have an .eml extension, but, in reality these are in MHTML format that is why Aspose.Words is able to load these files into it’s DOM. To detect and return the information about a format of a document stored in a disk file please use FileFormatUtil.DetectFileFormat method. Please let me know if I can be of any further assistance.

Best regards,