Essential Presentation是一款.NET类库,可以利用该类库帮助开发人员创建、读取和写入Microsoft PowerPoint 文件,该类库可以用于Windows Forms, WPF, ASP.NET, and ASP.NET MVC等平台下,该产品是一个无图形界面的,完全利用代码对PPT文件进行各种操作,支持打开、修改和保存PPT,可以转换PPT为PDF和图片,可以在PPT文件里创建图表,并且转换PPT文件里的图表为图片。开发人员也可以对PPT文件进行加密和解密、自定义文档属性等。这批文章主要介绍怎么利用Essential Presentation对PPT文件进行转换:
1、转换PPT文件为PDF文件
//Opens a PowerPoint presentation file
IPresentation presentation = Presentation.Open(fileName);
//Creates an instance of ChartToImageConverter and assigns it to ChartToImageConverter property of Presentation
presentation.ChartToImageConverter = new ChartToImageConverter();
//Converts the PowerPoint presentation into PDF document
PdfDocument PDFdocument = PresentationToPdfConverter.Convert(presentation);
//Saves the PDF document
PDFdocument.Save(@"Sample.pdf");
//Closes the PDF document
PDFdocument.Close(true);
//Closes the presentation
presentation.Close();
2.转换PPT文件为PDF文件
//Opens a PowerPoint presentation file
IPresentation presentation = Presentation.Open(fileName);
//Creates an instance of ChartToImageConverter
presentation.ChartToImageConverter = new ChartToImageConverter();
//Sets the scaling mode as best
presentation.ChartToImageConverter.ScalingMode =
Syncfusion.OfficeChart.ScalingMode.Best;
//Converts the first slide into image
Image image = presentation.Slides[0].ConvertToImage(
Syncfusion.Drawing.ImageType.Metafile);
//Saves the image as file
image.Save("slide1.png");
//Disposes the image
image.Dispose();
//Closes the presentation instance
presentation.Close();