)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to convert EML or MSG to PDF

Platform: WinForms |
Control: PDF |
Published Date: January 5, 2016 |
Last Revised Date: May 7, 2019

Syncfusion HTML to PDF for .NET used to convert webpages, SVG, MHTML, and HTML to PDF. Using this library, you can convert EML or MSG to PDF using C# and VB.NET.

Assemblies required

  • Syncfusion.Compression.Base.dll
  • Syncfusion.HtmlConverter.Base.dll
  • Syncfusion.Pdf.Base.dll
  • QtBinaries folder

You can get all the previously mentioned assemblies and QtBinaries by installing the HTML converter installer available in the following link.

HTML converterhttps://www.syncfusion.com/downloads/latest-version

Steps to convert EML or MSG to PDF programmatically:

  1. Create a new C# Windows Forms application project. Create new windows forms application
  2. Install the Syncfusion.HtmlToPdfConverter.QtWebKit.WinForms NuGet package as reference to your .NET Framework application from NuGet.org. Install required nuget packages
  3. Copy the QtBinaries folder from the installed HtmltoPdfConverter package and paste it into the folder, which contains the EML_MSG_To_PDF.csproj file. QtBinaries location Paste location for QtBinaries
  4. Include the following namespaces in the Form1.Designer.cs file.

C#

using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
using MsgReader;
using System.IO;

 

VB.NET

Imports Syncfusion.HtmlConverter
Imports Syncfusion.Pdf
Imports MsgReader
Imports System.IO

 

  1. Use the following code snippet to convert EML or MSG to PDF.

C#

string filePath = @"../../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 HTML to PDF converter 
    HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
    WebKitConverterSettings settings = new WebKitConverterSettings();
    //Set page margins
    settings.Margin.All = 0;                
    //Set WebKit path
    settings.WebKitPath = @"../../QtBinaries/";
    //Avoid splitting the text/images across the pages
    settings.SplitTextLines = false;
    settings.SplitImages = false;
    //Assign WebKit settings to HTML converter
    htmlConverter.ConverterSettings = settings;
    //Convert URL to PDF
    PdfDocument document = htmlConverter.Convert(files[0]);
    //Save and close the PDF document 
    document.Save("Output.pdf");
    document.Close(true);
 }

 

VB.NET

Dim filePath As String = "../../Data/MsgReaderContent.msg"
'Convert EML/MSG to HTML using third party reader
Dim msgReader As Reader = New Reader
Dim tempFolder As String = GetTemporaryFolder()
'File contains the HTML file converted from MSG
Dim files() As String = msgReader.ExtractToFolder(filePath, tempFolder)
Dim error1 As String = msgReader.GetErrorMessage
If Not String.IsNullOrEmpty(error1) Then
      Throw New Exception(error1)
End If
'Converts the HTML to PDF using WebKit rendering engine
If Not String.IsNullOrEmpty(files(0)) Then
      'Initialize HTML to PDF converter 
      Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)
      Dim settings As WebKitConverterSettings = New WebKitConverterSettings
      'Set page margins
      settings.Margin.All = 0
      'Set WebKit path
      settings.WebKitPath = "../../QtBinaries/"
      'Avoid splitting the text/images across the pages
      settings.SplitTextLines = False
      settings.SplitImages = False
      'Assign WebKit settings to HTML converter
      htmlConverter.ConverterSettings = settings
      'Convert URL to PDF
      Dim document As PdfDocument = htmlConverter.Convert(files(0))
      'Save and close the PDF document 
      document.Save("Output.pdf")
      document.Close(True)
End If

A complete working sample can be downloaded from EML_MSG_To_PDF.zip

By executing the program, you will get the PDF document as follows. Screenshot of output PDF document

Take a moment to peruse the documentation for Converting HTML string to PDF, where you will find other options for URL to PDF, bookmarks, and hyperlinks.

A code project link for Reading an Outlook MSG File.

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Jordan Capa
Apr 23, 2019

This information and instructions are very clear and helpful! If you're looking for a very fast pdf sdk software, try ZetPDF.com. It's really convenient and easy to use.

Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon