网站首页 博客 C#将ppt转换成图片
由于需要用到Aspose.Slides.dll,所以先添加引用

属性和函数定义
private string current_fullpath = ""; //文件完整路径
private string current_dirname = ""; //文件所在目录
private string current_filename = ""; //文件名(不包含后缀)
private string current_fileext = ""; //文件后缀
private int current_totalpage = 0; //转换后的图片数量
private string office2ext = "png"; //转换后的图片保存类型
private string logtext; //日志信息
//将PPT转换成图片
private void ConvertPPT2Image()
{
Aspose.Slides.Presentation ppt = null;
try
{
ppt = new Aspose.Slides.Presentation(this.current_fullpath);
}
catch (Exception e)
{
this.logtext = ", " + e.Message + "。";
messagetextBox.AppendText(this.logtext);
messagetextBox.ScrollToCaret();
}
if (ppt != null)
{
try
{
ppt.Save(this.current_dirname + "\\" + this.current_filename + ".pdf", Aspose.Slides.Export.SaveFormat.Pdf);
this.current_fullpath = this.current_dirname + "\\" + this.current_filename + ".pdf";
this.current_fileext = "pdf";
this.ConvertPdf2Image();
}
catch (Exception e)
{
this.logtext = ", " + e.Message + ", 转成pdf时失败。";
messagetextBox.AppendText(this.logtext);
messagetextBox.ScrollToCaret();
}
}
else
{
this.logtext = ", 文件无效或者被加密。";
messagetextBox.AppendText(this.logtext);
messagetextBox.ScrollToCaret();
}
}调用方法
this.current_fullpath = "E:/file/test3.pptx"; //文件完整路径
this.current_fullpath = Path.GetFullPath(this.current_fullpath.Replace("/", "\\\\")); //斜杠替换
this.current_dirname = Path.GetDirectoryName(this.current_fullpath); //文件所在目录
this.current_filename = Path.GetFileNameWithoutExtension(this.current_fullpath); //文件名(不包含后缀)
this.current_fileext = "pptx"; //文件后缀
this.ConvertPPT2Image();注意事项
将ppt转换成图片不是一步完成的,中间先转换成了pdf,然后再转换成的图片。
将pdf转换成图片的方法详见这里