【发布时间】:2017-02-01 12:55:26
【问题描述】:
我们正在尝试使用 Powerpoint Office Interop 将 PPT 文件转换为 PDF。我们正在使用ExportAsFixedFormat() 进行转换,如下面的代码 sn-p 所示:
public static void ConvertPowerPointToPdf(string inputFile)
{
string outputFileName = @"C:\All format files\PPT2PDF.pdf";
Microsoft.Office.Interop.PowerPoint.Application powerPointApp =
new Microsoft.Office.Interop.PowerPoint.Application();
Presentation presentation = null;
Presentations presentations = null;
try
{
presentations = powerPointApp.Presentations;
presentation = presentations.Open(inputFile, MsoTriState.msoFalse, MsoTriState.msoFalse,
MsoTriState.msoFalse);
presentation.PageSetup.SlideSize = PpSlideSizeType.ppSlideSizeA4Paper; //It throws the exception here
presentation.ExportAsFixedFormat(outputFileName, PpFixedFormatType.ppFixedFormatTypePDF,
PpFixedFormatIntent.ppFixedFormatIntentPrint);
}
catch (Exception)
{
throw;
}
}
如果我们不设置 SlideSize 属性,上面的代码可以正常工作。当我们尝试设置SlideSize 属性时,异常被抛出为“PageSetup(未知成员):失败。”报错信息截图如下:
Microsoft.Office.Interop.PowerPoint版本为15.0.0.0,Microsoft Office 15.0 Object Library作为Office核心库使用。我的电脑在 Windows 8.1 中,我使用的是 Microsoft Office 2013。由于我们需要自定义输出格式,我们需要设置当前抛出异常的 SlideSize 属性。
【问题讨论】:
标签: c# interop powerpoint office-interop com-interop