C# .NET Core 5.0 将 PPTX 文件转换为 PDF 文件
要将 .pptx 文件转换为 PDF 文件,可以使用以下步骤:
-
安装 Microsoft.Office.Interop.PowerPoint NuGet 包。
-
在代码中使用 Microsoft.Office.Interop.PowerPoint 库来打开 .pptx 文件。
-
使用 SaveAsPDF 方法将打开的 .pptx 文件另存为 PDF 文件。
以下是示例代码:
using Microsoft.Office.Interop.PowerPoint;
// 打开 .pptx 文件
var app = new Application();
var presentation = app.Presentations.Open(@"C:\path\to\file.pptx");
// 将文件另存为 PDF
presentation.SaveAs(@"C:\path\to\file.pdf", PpSaveAsFileType.ppSaveAsPDF);
// 关闭文件和应用程序
presentation.Close();
app.Quit();
注意:在使用 Microsoft.Office.Interop.PowerPoint 库时,需要在计算机上安装 Microsoft PowerPoint 应用程序。
原文地址: https://www.cveoy.top/t/topic/omXZ 著作权归作者所有。请勿转载和采集!