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