我有 1000 封电子邮件(.msg 格式),我想将它们转换为 PDF 文件。
阅读 .MSG 文件已经被问到这里。
但对我来说,问题是像从“文件 - > 打印”一样打印 .msg 电子邮件。
有没有一种简单的方法可以将 .msg 电子邮件打印为 PDF?
如果您希望以编程语言实现解决方案,而不是手动打印每条消息,您可以考虑使用 Aspose.Network 和 Aspose.Words for .NET 组件。他们一起工作将 MSG 文件转换为 PDF。
查看此页面上的示例代码。它对 TIFF 进行 MSG,但您可以稍微修改并提供任何支持的格式,包括 PDF、DOC、DOCX 等。
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