EML or MSG files can be converted to HTML using code available in this Code project article.
Syncfusion WebKit converter can be used to convert HTML to PDF.
// Code
string filePath = Path.GetFullPath("../../Data/MsgReaderContent.msg");
//Convert EML/MSG to HTML using third party reader
var msgReader = new Reader();
string tempFolder = GetTemporaryFolder();
//File contains the HTML file converted from MSG.
var files = msgReader.ExtractToFolder(filePath, tempFolder);
var error = msgReader.GetErrorMessage();
if (!string.IsNullOrEmpty(error))
throw new Exception(error);
//Converts the HTML to PDF using WebKit rendering engine.
if (!string.IsNullOrEmpty(files[0]))
{
//Initialize WebKit HTML with WebKit rendering engine.
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
WebKitConverterSettings settings = new WebKitConverterSettings();
string WebKitBinaryPath ="../../QtBinaries/";
//WebKit assembly path
settings.WebKitPath = WebKitBinaryPath;
//Assign converter settings
htmlConverter.ConverterSettings = settings;
// Convert to PDF document.
PdfDocument document = htmlConverter.Convert(files[0]);
//Add cover page
PdfPage page = new PdfPage();
document.Pages.Insert(0, page);
PdfFont font = new PdfTrueTypeFont(new Font("Helvetica", 16, FontStyle.Bold), true);
PdfSolidBrush brush = new PdfSolidBrush(Color.FromArgb(44, 71, 120));
page.Graphics.DrawString("cover page",font,brush,new PointF());
//Insert attachments
for (int i = 1; i < files.Length; i++)
{
FileInfo file = new FileInfo(files[i]);
document.Attachments.Add(AddAttachment(file));
}
// Save and close the document.
document.Save("Output.pdf");
document.Close(true);
private PdfAttachment AddAttachment(FileInfo f)
{
PdfAttachment attachment = new PdfAttachment(f.FullName);
attachment.ModificationDate = DateTime.Now;
attachment.Description = f.Name;
attachment.MimeType = "application/" + f.Extension;
//returns the attachment to the document
return attachment;
}
A complete sample application is also available here
The whole suite of controls and libraries is available for free through the community license program if you qualify (less than 1 million USD in revenue). Note: I work for Syncfusion.