要将 .pptx 文件转换为 PDF 文件,可以使用以下步骤:

  1. 安装 Microsoft.Office.Interop.PowerPoint NuGet 包。

  2. 使用以下代码将 .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');
  1. 使用以下代码将 PowerPoint 文件另存为 PDF 文件:
// Save the presentation as a PDF file
presentation.ExportAsFixedFormat('C:\path\to\output.pdf', PpFixedFormatType.ppFixedFormatTypePDF);
  1. 最后,关闭 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();
    }
}
C# .NET Core 5.0 将 PPTX 转换为 PDF 文件

原文地址: https://www.cveoy.top/t/topic/omXm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录