C# PPT转PDF代码示例 - 快速将PPT转换为PDF
以下是用C#编写的PPT转PDF程序示例,使用Microsoft Office Interop库实现转换。需要在项目中添加对Microsoft PowerPoint和Microsoft Word的引用。
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Interop.Word;
using System;
using System.IO;
namespace PPTtoPDF
{
class Program
{
static void Main(string[] args)
{
string pptPath = @"C:\path\to\ppt\file.pptx";
string pdfPath = @"C:\path\to\pdf\file.pdf";
// 创建新的PowerPoint应用程序实例
Application pptApplication = new Application();
// 打开PowerPoint演示文稿
Presentation pptPresentation = pptApplication.Presentations.Open(pptPath, WithWindow: MsoTriState.msoFalse);
// 将演示文稿保存为PDF
pptPresentation.ExportAsFixedFormat(pdfPath, PpFixedFormatType.ppFixedFormatTypePDF);
// 关闭演示文稿并退出PowerPoint应用程序
pptPresentation.Close();
pptApplication.Quit();
Console.WriteLine("PPT to PDF conversion completed successfully.");
}
}
}
运行程序后,将在指定的输出路径中生成一个PDF文件。
原文地址: https://www.cveoy.top/t/topic/nmEt 著作权归作者所有。请勿转载和采集!