Outlook.MailItem另存为pdf打不开
Outlook.MailItem save as pdf can't be open
当我从 outlook 单击发送按钮时,我试图将我的电子邮件以 pdf 格式保存到特定文件夹。我的代码如下所示。可以看到文件保存成功,但是打不开。我的代码有什么问题吗? office版本是2016.
private void Application_ItemSend(object Item, ref bool Cancel)
{
mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
string title = mailItem.Subject;
mailItem.SaveAs("c://" + title + ".pdf", OlBodyFormat.olFormatRichText);
}
谢谢
MailItemclass的SaveAs方法接受两个参数,第二个是
要保存的文件类型可以是以下 OlSaveAsType 常量之一:olHTML、olMSG、olRTF、olTemplate、olDoc、olTXT、olVCal、olVCard、olICal 或 olMSGUnicode。如您所见,没有使用 .pdf 文件格式保存消息的选项。
但是,您可以考虑使用 Word 对象模型来完成这项工作。
TheDocument.ExportAsFixedFormat(
docName.Replace(".docx", ".pdf"),
Word.WdExportFormat.wdExportFormatPDF,
OptimizeFor: Word.WdExportOptimizeFor.wdExportOptimizeForOnScreen,
BitmapMissingFonts: true, DocStructureTags: false);
有关 WordEditor
属性 Inspector class 的更多信息 ExportAsFixedFormat method of the Document class allows to save a document as PDF or XPS format. See Chapter 17: Working with Item Bodies。
作为最后的手段,您可以考虑使用任何第三方 .Net 组件从文本或 HTML/RTF 标记创建 PDF 文档。
当我从 outlook 单击发送按钮时,我试图将我的电子邮件以 pdf 格式保存到特定文件夹。我的代码如下所示。可以看到文件保存成功,但是打不开。我的代码有什么问题吗? office版本是2016.
private void Application_ItemSend(object Item, ref bool Cancel)
{
mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
string title = mailItem.Subject;
mailItem.SaveAs("c://" + title + ".pdf", OlBodyFormat.olFormatRichText);
}
谢谢
MailItemclass的SaveAs方法接受两个参数,第二个是 要保存的文件类型可以是以下 OlSaveAsType 常量之一:olHTML、olMSG、olRTF、olTemplate、olDoc、olTXT、olVCal、olVCard、olICal 或 olMSGUnicode。如您所见,没有使用 .pdf 文件格式保存消息的选项。
但是,您可以考虑使用 Word 对象模型来完成这项工作。
TheDocument.ExportAsFixedFormat(
docName.Replace(".docx", ".pdf"),
Word.WdExportFormat.wdExportFormatPDF,
OptimizeFor: Word.WdExportOptimizeFor.wdExportOptimizeForOnScreen,
BitmapMissingFonts: true, DocStructureTags: false);
有关 WordEditor
属性 Inspector class 的更多信息 ExportAsFixedFormat method of the Document class allows to save a document as PDF or XPS format. See Chapter 17: Working with Item Bodies。
作为最后的手段,您可以考虑使用任何第三方 .Net 组件从文本或 HTML/RTF 标记创建 PDF 文档。