打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
PPT导出为图片

使用Aspose组件导出

Aspose有Aspose.Slides.dll,可以无需安装office,进行读写PPT文件。

Aspose可能通过Aspose.Slides.NET安装

简单的导出图片demo,如下:

 1     internal class PptToImagesConverter 2     { 3         private const string ImageExtension = ".png"; 4         public bool ConvertToImages(string pptFile, string exportImagesFolder) 5         { 6             using (Presentation pres = new Presentation(pptFile)) 7             { 8                 int desiredX = 1200; 9                 int desiredY = 800;10 11                 float scaleX = (float)(1.0 / pres.SlideSize.Size.Width) * desiredX;12                 float scaleY = (float)(1.0 / pres.SlideSize.Size.Height) * desiredY;13 14                 foreach (ISlide sld in pres.Slides)15                 {16                     Bitmap bmp = sld.GetThumbnail(scaleX, scaleY);17 18                     string slidePath = Path.Combine(exportImagesFolder,$"Slide_{sld.SlideNumber}.{ImageExtension}");19                     bmp.Save(slidePath, System.Drawing.Imaging.ImageFormat.Png);20                 }21             }22 23             return true;24         }25     }

注:以上途径是没有购买过的dll,生成的图片会有水印。使用正版购买的,应该不会有问题。

使用Interop.PowerPoint导出

也是在Nuget中搜索并安装:

另,通过Presentations.Open("c:\test.pptx::PASSWORD::")可以解密PPT,从而导出图片。 

 1     internal class PptToImagesConverter1 2     { 3         private const string PASSWORD_MARK = "::PASSWORD::"; 4         private const string ImageExtension = ".png"; 5         public bool ConvertToImages(string pptFile, string exportImagesFolder) 6         { 7             var tempPpt = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + Path.GetExtension(pptFile)); 8             File.Copy(pptFile, tempPpt); 9             Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application();10             Microsoft.Office.Interop.PowerPoint.Presentation presentation = app.Presentations.Open(tempPpt + PASSWORD_MARK, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);11             int desiredX = 1200;12             int desiredY = 800;13             var slides = ((Microsoft.Office.Interop.PowerPoint.Presentation)presentation).Slides.Cast<Microsoft.Office.Interop.PowerPoint.Slide>().ToList();14             Parallel.ForEach(slides, slide =>15             {16                 string slidePath = Path.Combine(exportImagesFolder, "Slide-" + slide.SlideIndex + ImageExtension);17                 slide.Export(slidePath, ImageExtension, desiredX, desiredY);18             });19             return true;20         }21     }

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C#实现 word、pdf、ppt 转为图片
Microsoft.Office.Core 引用以及 Microsoft.Office.Core.MsoTriState 的问题
Asp.net常见word excel ppt pdf在线预览方案
c# 文件类型转换汇总(word/excel/ppt/txt/pdf 转HTML&word/ppt 转swf)
Upload Any File (“txt, doc, docx, xls, xlsx, ppt, pptx, rtf”) and Show the Thumbnail of First Page o
C#实现向excel中插入行列,以及设置单元格合并居中效果
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服