Hi Manuel,
There is no direct method of printing .msg file to pdf, but you can use the following code create a pdf document from the msg file. This code uses Aspose.Network and Aspose.Pdf libraries.
You can modify the code to include other details if required.
public
string strOutlookFile = "c:\\outlook.msg";
public string strPdfFile = "c:\\outlook.pdf";
// load the message
MailMessage mail = MailMessage.Load(strOutlookFile, MessageFormat.Msg);
// create the header and body
StringBuilder sb = new StringBuilder();
sb.AppendLine(
"From:\t\t" + mail.From.ToString());
sb.AppendLine(
"Sent:\t\t" + mail.Date.ToLongDateString() + " " + mail.Date.ToLongTimeString());
sb.AppendLine(
"To:\t\t" + mail.To.ToString());
if (mail.CC.Count >= 0)
sb.AppendLine(
"Cc:\t\t" + mail.CC.ToString());
sb.AppendLine(
"Subject:\t" + mail.Subject);
sb.AppendLine(); sb.AppendLine(); sb.AppendLine(); sb.AppendLine();
// create pdf doc
Aspose.Pdf.Pdf pdf1 =
new Aspose.Pdf.Pdf();
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();
// create text paragraph
Aspose.Pdf.Text text =
new Aspose.Pdf.Text(sb.ToString() + mail.TextBody);
// save pdf file
sec1.Paragraphs.Add(text);
pdf1.Save(strPdfFile);
Best Regards,
Saqib Razzaq
Support Developer
Aspose Guangzhou Team