使用Aspose组件导出

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

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

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

     internal class PptToImagesConverter
{
private const string ImageExtension = ".png";
public bool ConvertToImages(string pptFile, string exportImagesFolder)
{
using (Presentation pres = new Presentation(pptFile))
{
int desiredX = ;
int desiredY = ; float scaleX = (float)(1.0 / pres.SlideSize.Size.Width) * desiredX;
float scaleY = (float)(1.0 / pres.SlideSize.Size.Height) * desiredY; foreach (ISlide sld in pres.Slides)
{
Bitmap bmp = sld.GetThumbnail(scaleX, scaleY); string slidePath = Path.Combine(exportImagesFolder,$"Slide_{sld.SlideNumber}.{ImageExtension}");
bmp.Save(slidePath, System.Drawing.Imaging.ImageFormat.Png);
}
} return true;
}
}

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

使用Interop.PowerPoint导出

也是在Nuget中搜索并安装:

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

     internal class PptToImagesConverter1
{
private const string PASSWORD_MARK = "::PASSWORD::";
private const string ImageExtension = ".png";
public bool ConvertToImages(string pptFile, string exportImagesFolder)
{
var tempPpt = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + Path.GetExtension(pptFile));
File.Copy(pptFile, tempPpt);
Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application();
Microsoft.Office.Interop.PowerPoint.Presentation presentation = app.Presentations.Open(tempPpt + PASSWORD_MARK, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
int desiredX = ;
int desiredY = ;
var slides = ((Microsoft.Office.Interop.PowerPoint.Presentation)presentation).Slides.Cast<Microsoft.Office.Interop.PowerPoint.Slide>().ToList();
Parallel.ForEach(slides, slide =>
{
string slidePath = Path.Combine(exportImagesFolder, "Slide-" + slide.SlideIndex + ImageExtension);
slide.Export(slidePath, ImageExtension, desiredX, desiredY);
});
return true;
}
}

最新文章

  1. 用WPF实现查找结果高亮显示
  2. SQLAlchemy一对多总结
  3. sqlite_
  4. 将Html文档整理为规范XML文档
  5. Supervisor 守护 dotnetcore 程序
  6. linux网络故障解决方法
  7. mongodb持久化
  8. [Linux]学习笔记(3)-uname的用法
  9. paip.索引优化---sql distict—order by 法
  10. MysqL的root用户不允许远程连接
  11. Storm源码分析--Nimbus-data
  12. 读苹果开发文档时遇到瓶颈,转而花2天看了Objc基本语法
  13. 1014 Uniform Generator
  14. 使用jquery.form.js文件进行文件上传
  15. 安装selenium
  16. Docker build Dockerfile 构建镜像 - 二
  17. Vue2.0 新手完全填坑攻略—从环境搭建到发布
  18. hdoj:2033
  19. cmd--登录mysql
  20. jQuery Validation Plugin

热门文章

  1. HBase的安装、配置与实践
  2. Knative 简介
  3. airtest启用本地python环境的方法
  4. CSS-10-内边距
  5. linux---&gt;阿里云centos6.9环境配置安装lnmp
  6. canvas跨域完美解决,微信头像解决跨域
  7. Centos 7 部署lnmp集群架构
  8. 一、Shell概述
  9. centos7 配置虚拟交换机(物理交换机truck端口设置)(使用brctl)
  10. 【5min+】 这些C#的运算符您都认识吗?