如果直接轉圖片,會很模糊
采用先將ppt轉pdf,在通過pdf轉圖片,這樣出來的結果就非常清晰
var pptFileName = "公司網絡及計算機使用與要求.pptx"; Presentation ppt = new Presentation(pptFileName); Stream st=new MemoryStream(); ppt.Save(st,SaveFormat.Pdf); Aspose.Pdf.Document document = new Aspose.Pdf.Document(st); var device = new Aspose.Pdf.Devices.JpegDevice(); //默認質量為100,設置質量的好壞與處理速度不成正比,甚至是設置的質量越低反而花的時間越長,懷疑處理過程是先生成高質量的再壓縮 device = new Aspose.Pdf.Devices.JpegDevice(100); //遍歷每一頁轉為jpg for (var i = 1; i <= document.Pages.Count; i++) { string filePathOutPut = Path.Combine("images", string.Format("{0}.jpg", i)); FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate); try { device.Process(document.Pages[i], fs); fs.Close(); } catch (Exception ex) { fs.Close(); // File.Delete(filePathOutPut); } }
注意,aspose新的版本加載ppt都是一樣的代碼:
Presentation ppt = new Presentation(pptFileName);
比較老的版本對於ppt的版本有區別,
如果后綴名是ppt,那么使用:
Presentation ppt = new Presentation(pptFileName);
如果后綴名是pptx,那么使用:
PresentationEx ppt = new PresentationEx(pptFileName);
怎樣區分aspose的版本是老的還是新的呢,有一個笨辦法,查看有沒有PresentationEx 這個類,如果有,那么是老版本,沒有就是新版本。
