1. Products
  2.   Conholdate.Total
  3.   .NET
  4.   OFT to PDF Conversion

Convert OFT Headers to PDF with C#

Email to PDF conversion using .NET Core libraries

Download

.NET C# Conversion of OFT to PDF

  • Load the OFT message file with MailMessage.Load method
  • Create an instance of MhtSaveOptions for output customization
  • Set to write message header with complete email addresses
  • Call MailMessage.Save method to save the message in MHTML format
  • Load MHTML from previous step in an instance of Document
  • Call Document.Save method with SaveFormat.Pdf as second parameter
  • Load the PDF in any application to view message template as PDF

Get Started with .NET Core APIs

The namespaces required for the following piece of code are Aspose.Email & Aspose.Words. You can get the respective assembly files from the downloads or fetch the whole package from NuGet.

OFT to PDF conversion can be done on different operating systems such as Windows, Linux or macOS while using platforms such as Windows Azure, Mono and Xamarin.

// load message with an instance of MailMessage
var mailMsg = Aspose.Email.MailMessage.Load("message.oft");
// create an instance of MhtSaveOptions for MTHML customization
var mhtSaveOptions = Aspose.Email.MhtSaveOptions.DefaultMhtml;
// set MhtSaveOptions to write headers with complete email addresses
mhtSaveOptions.MhtFormatOptions = Aspose.Email.MhtFormatOptions.WriteHeader | Aspose.Email.MhtFormatOptions.WriteCompleteEmailAddress;
// temporarily save the MTHML in MemoryStream
using (var stream = new System.IO.MemoryStream())
{
    mailMsg.Save(stream, mhtSaveOptions);

    // load the MHTML stream in an instance of Document
    var doc = new Aspose.Words.Document(stream);
    doc.Save("output.pdf");
}
// load the resultant PDF in default application
System.Diagnostics.Process.Start("output.pdf");

Other Supported Conversions

EML TO PDF

(Outlook Message Item File)

MSG TO PDF

(Microsoft Outlook Email Format)

EMLX TO PDF

(Apple Mail File Format)

PST TO PDF

(Outlook Personal Storage)

About OFT File Format

OFT files are templates created with Microsoft Outlook. OFT are used to send emails with common information to save time. Such files can be generated by creating a new email, adding necessary information and then using the Save As Office Template (.oft) dropdown from Microsoft Outlook.

Read More