4

I'm writing a small program for pdf edit. This program may to print label in one specific place on first pdf page. Files which are edit are select by drag and drop. Everything is fine, but I need to write function which convert file to pdf before print label if it's .msg. I wrote convert function docx to pdf, and it's work to, but I totally dont know how to convert .msg to .pdf, i try to do this with outlook library, but i can't. This is how i convert docx to pdf:

Microsoft.Office.Interop.Word.Document wordDoc { get; set; }

void doc_to_pdf()
{
    Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
    wordDoc = app.Documents.Open(openFD.FileName);
    wordDoc.ExportAsFixedFormat(to_pdf(openFD.FileName), Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);

    wordDoc.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges);
    app.Quit();

    Marshal.ReleaseComObject(wordDoc);
    Marshal.ReleaseComObject(app);
    openFD.FileName = to_pdf(openFD.FileName);
}

openFD.FileName is a file path

And this is how i try to convert msg to pdf

Microsoft.Office.Interop.Outlook.MailItem outMsg;

void msg_to_pdf()
{
    Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
    outMsg = //i dont know how to open here this file

    string fileName = System.IO.Path.GetFullPath(openFD.FileName);
    outMsg.SaveAs(to_pdf(openFD.FileName), Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSG);
}

I try a lot of ways to do this, but i can't. Is there anyone who can do this? Or who can tell me how to do this? Please help me, it is really important.

CSDev
  • 3,177
  • 6
  • 19
  • 37

0 Answers0