开发者

How to print .MSG into PDF

I have 1000 emails (in .msg format) and I'd like to convert those to PDF files.

Reading .MSG file has already been asked here.

But the problem for me is to print .msg emails as you do from "File -> Print".

Is there a simple way to pri开发者_运维知识库nt .msg emails to PDF?


If you want a solution implemented in a programming language instead of manually printing each message, you may consider using Aspose.Network and Aspose.Words for .NET components. They work together to convert MSG file to PDF.

  1. Aspose.Network for .NET for loading the MSG and saving as MHTML format
  2. Aspose.Words for .NET for loading the MHTML and producing the PDF or any other supported format

Have a look at the sample code at this page. It does MSG to TIFF, but you may slightly modify and give any supported format including PDF, DOC, DOCX etc.


    Dim objItem, objFSO, strFile, input, fileExt, strHtml, strPdf, msg,    wordDoc, wordApp, tempFileFolder

    Const olFormatHTML = 5
    Const wdFormatPDF = 17


    input = Wscript.Arguments(0)

    ' Create a File System object
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )

     ' Check if the Word document exists
    If objFSO.FileExists(input) Then
        Set objItem = objFSO.GetFile(input)
        strFile = objItem.Path  
    Else
        WScript.Echo "FILE OPEN ERROR: The file does not exist" & vbCrLf
        WScript.Quit
    End If

    fileExt = Right(strFile,3)

    If fileExt <> "msg" Then
        WScript.Echo "FILE ERROR: The file extension is not .msg" & vbCrLf
        WScript.Quit
    End If

    strHtml = objItem.Path + ".html"
    strPdf = objItem.Path + ".pdf"

    Set Outlook = CreateObject("Outlook.Application")
    Set msg = Outlook.CreateItemFromTemplate(objItem.Path) 
    msg.SaveAs strHtml, olFormatHTML
    Outlook.Quit

    Set wordApp = CreateObject( "Word.Application" )    
    wordApp.Documents.Open strHtml
    Set wordDoc = wordApp.ActiveDocument
    wordDoc.SaveAs strPdf, wdFormatPDF
    wordDoc.Close
    wordApp.Quit


    If objFSO.FileExists(strHtml) Then
        objFSO.DeleteFile(strHtml)
    End If

    tempFileFolder = objItem.Path & "_files"
    If objFSO.FolderExists(tempFileFolder) Then
        objFSO.DeleteFolder(tempFileFolder)
    End If


You could use an application like MsgViewer Pro .

It has a "print from command line" feature which you could probably use in a batch mode.

Note: I did not use this viewer, but I thought it might be a good suggestion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜