繁体   English   中英

在.net中以编程方式将Power Point演示文稿转换为PDF

[英]Programmatically convert Power Point presentation to PDF in .net

经过一番搜索,我仍然没有我需要的东西。 我正在尝试使用VB.Net将各种文件转换为PDF,并将各种MS Office组件(如Word / Excel / PowerPoint)作为COM对象或通过使用PIA(Office Interop组件)进行引用。 最后,我想使用COM方法,因为它与版本无关,这很重要。

对于Word和Excel,我可以使其同时起作用。 但是对于PowerPoint,我遇到了问题,希望能提出一些建议。

这是两种方法

通讯

Dim appPP As Object = CreateObject("PowerPoint.Application")
Dim docPP As Object = appPP.Presentations.Open(strAttachmentFileName)
'2 is Microsoft.Office.Interop.PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF
docPP.ExportAsFixedFormat(strNewFileName, 2)
docPP.Close()
appPP.Quit()

此方法在“导出”行出现错误-类型不匹配。 (来自HRESULT的异常:0x80020005(DISP_E_TYPEMISMATCH))

PIA-可以

Imports Microsoft.Office.Interop
' PowerPoint requires this, to add a reference use COM - MS Office Type Library of same version as interop
Imports Microsoft.Office.Core 
Dim appPP As New PowerPoint.Application
Dim docPP As PowerPoint.Presentation = appPP.Presentations.Open(strAttachmentFileName)
docPP.ExportAsFixedFormat(strNewFileName, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF)
docPP.Close()
appPP.Quit()

编辑

同样在COM版本中,我尝试了完全合格的版本,包括对PIA和Office Core的引用,如下所示

docPP.ExportAsFixedFormat(strNewFileName,PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF,PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentScreen,MsoTriState.msoFalse,PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst,PowerPoint.PpPrintOutputType.ppPrint输出状态,pp。 ,False,False,False,False)

它仍然得到错误

在尝试了ExportAsFixedFormat的COM版本之后,我认为COM对象中存在错误。 我确实找到了可行的解决方案

docPP.SaveAs(strNewFileName, 32)

我不确定该版本的兼容性。 我有Office 2010。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM