How to print .MSG into PDF

断了今生、忘了曾经 提交于 2019-12-11 03:04:28

问题


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 print .msg emails to PDF?


回答1:


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.




回答2:


    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



回答3:


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.



来源:https://stackoverflow.com/questions/5223834/how-to-print-msg-into-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!