Convert emails (MSG/EML) to PDF in C#

This article explains how to convert email files such as MSG and EML to PDF.

Nutrient .NET SDK’s (formerly GdPicture.NET) conversion from email files to PDFs offers the following benefits:

  • Conversion from EML and MSG files to PDF without external libraries or dependencies such as Microsoft Office interop.
  • Support for embedding email attachments into the output PDF or PDF/A document as PDF attachment annotations.
  • Outstanding Unicode support.
  • Support for documents with mixed encoding and mixed right-to-left (RTL) and left-to-right (LTR) text.

This guide uses MSG files as an example. The process is the same for EML files.

Creating a PDF from an email file

To create a PDF from an MSG file, follow the steps below:

  1. Create a GdPictureDocumentConverter object.
  2. Load the source document by passing its path to the LoadFromFile method. Recommended: Specify the source document format with a member of the DocumentFormat enumeration.
  3. Save the output in a new PDF document with the SaveAsPDF method.

The example below creates a PDF document from an MSG file:

using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Load the source document.
gdpictureDocumentConverter.LoadFromFile(@"C:\temp\source.msg", GdPicture14.DocumentFormat.DocumentFormatMSG);
// Save the output in a new PDF document.
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");

Email attachments are automatically added to the output document as PDF attachment annotations.

To convert an email file to PDF/A for long-term preservation, specify the conformance level of the output PDF/A document by passing a member of the PdfConformance enumeration to the SaveAsPDF method.

Optional configuration properties

Optionally, configure the conversion with the following properties of the GdPictureDocumentConverter object:

The example below creates a PDF document from an MSG file with a custom configuration:

using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Load the source document.
gdpictureDocumentConverter.LoadFromFile(@"C:\temp\source.msg", GdPicture14.DocumentFormat.DocumentFormatMSG);
// Configure the conversion.
gdpictureDocumentConverter.EmailPreferOnePage = true;
// Save the output in a new PDF document.
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");

Used Methods and Properties

Related Topics