aspose ppt轉圖片


如果直接轉圖片,會很模糊
采用先將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);
                }
            }
View Code

注意,aspose新的版本加載ppt都是一樣的代碼:

Presentation ppt = new Presentation(pptFileName);

比較老的版本對於ppt的版本有區別,

如果后綴名是ppt,那么使用:

Presentation ppt = new Presentation(pptFileName);

如果后綴名是pptx,那么使用:

PresentationEx ppt = new PresentationEx(pptFileName);

 

怎樣區分aspose的版本是老的還是新的呢,有一個笨辦法,查看有沒有PresentationEx 這個類,如果有,那么是老版本,沒有就是新版本。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM