C# .NET Core 5.0 将 PPTX 转换为 PDF 文件
要将 .pptx 文件转换为 PDF 文件,可以使用以下步骤:
-
安装 Microsoft.Office.Interop.PowerPoint NuGet 包。
-
使用以下代码将 .pptx 文件加载到 PowerPoint 应用程序中:
using Microsoft.Office.Interop.PowerPoint;
// Load the PowerPoint presentation
var app = new Application();
var presentation = app.Presentations.Open('C:\path\to\presentation.pptx');
- 使用以下代码将 PowerPoint 文件另存为 PDF 文件:
// Save the presentation as a PDF file
presentation.ExportAsFixedFormat('C:\path\to\output.pdf', PpFixedFormatType.ppFixedFormatTypePDF);
- 最后,关闭 PowerPoint 应用程序并释放资源:
// Clean up resources
presentation.Close();
app.Quit();
完整代码示例:
using Microsoft.Office.Interop.PowerPoint;
class Program
{
static void Main(string[] args)
{
// Load the PowerPoint presentation
var app = new Application();
var presentation = app.Presentations.Open('C:\path\to\presentation.pptx');
// Save the presentation as a PDF file
presentation.ExportAsFixedFormat('C:\path\to\output.pdf', PpFixedFormatType.ppFixedFormatTypePDF);
// Clean up resources
presentation.Close();
app.Quit();
}
}
原文地址: https://www.cveoy.top/t/topic/omXm 著作权归作者所有。请勿转载和采集!