以编程方式将MSG转换为PDF [英] Converting MSG to PDF programmatically
问题描述
您好编码员,
因此我将MSG转换为PDF文件时遇到问题。这是我目前的代码:
Hello coders,
So I have a problem with the conversion of MSG to PDF files. Here is my code currently:
If TypeOf objItem Is Outlook.MailItem Then
Dim EmailMessages As String = "EmailMessages"
If Not Directory.Exists(strDest + "\" + EmailMessages) Then
Directory.CreateDirectory(strDest + "\" + EmailMessages)
End If
'save it as MSG (native)
MItem = CType(objItem, Outlook.MailItem)
Dim rTime As String = Format(MItem.ReceivedTime, "dd.MMM.yyyy (hh.mm.ss tt)")
MItem.SaveAs(strFolderPath & "\" + MItem.SenderName.ToString + " " + rTime + ".msg", Outlook.OlSaveAsType.olMSG)
'save it as PDF
MItem.SaveAs(strFolderPath & "\" + MItem.SenderName.ToString + " " + rTime + ".html", Outlook.OlSaveAsType.olHTML)
strPathPDF = strFolderPath & "\" + MItem.SenderName.ToString + " " + rTime
wordDoc = wordApp.Documents.Open(strPathPDF + ".html")
wordDoc.ExportAsFixedFormat(strPathPDF + ".pdf", Word.WdExportFormat.wdExportFormatPDF)
wordDoc.Close()
End If
MITEM是我对MailItems的占位符。 />
问题是我想直接从MSG到PDF。我理解单独使用Office女士是不可能的。我遇到过Foxit PDF创建者,它本质上是一个打印机驱动程序,可以打印出PDF文件。这是一个很好的,但是Printout()方法不带任何参数,所以我简化了输入文件名并选择目录并单击手动保存。我不想这样做。有没有办法超越这个印刷品。或者更好的是,有没有办法在没有任何第三方软件的情况下做到这一点?任何帮助将不胜感激:D
问候,
Adeeb
MITEM is my placeholder for MailItems.
Problem is I want to do it directly from MSG to PDF. I understand this isn't possible with Ms Office alone. I have come across Foxit PDF creator which is essentially a printer driver which can print out PDF's to file. This is great an all but the Printout() method doesn't take any arguments so I am reduced to typing in the file name and choosing the directory and clicking save manually. I do not want to do this. Is there a way to get past this printing thing. Or better yet is there a way to do this without any 3rd party software? Any help will be appreciated :D
Regards,
Adeeb
推荐答案
您可以查看PDFSharp - http://pdfsharp.codeplex.com/ [< a href =http://pdfsharp.codeplex.com/target =_ blanktitle =New Window> ^ ]。
顺便说一句,在下面的代码中,为什么不直接保存为pdf而不是HTML格式? OLSaveAsType中没有其他选项吗?
'将其另存为PDF
MItem.SaveAs(strFolderPath&\ + MItem.SenderName.ToString ++ rTime +。html,Outlook.OlSaveAsType.olHTML)
You can have a look at PDFSharp - http://pdfsharp.codeplex.com/[^].
BTW, in below code why are you not saving directly to pdf instead of HTML format? Is there not an other option in the OLSaveAsType?
'save it as PDF
MItem.SaveAs(strFolderPath & "\" + MItem.SenderName.ToString + " " + rTime + ".html", Outlook.OlSaveAsType.olHTML)
这篇关于以编程方式将MSG转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!