翻譯|使用教程|編輯:李顯亮|2020-10-26 10:05:25.723|閱讀 635 次
概述:在本文中,將展示如何使用Java將PPTX中的幻燈片轉換為JPG圖像。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
MS PowerPoint演示文稿不能直接從Web或桌面應用程序中顯示。一種可能的解決方案是將PPTX演示文稿中的幻燈片轉換為JPEG或PNG等圖像。
>>你可以點擊這里下載Aspose.Slides for Java v20.10測試體驗。(安裝包僅提供部分功能,并設置限制,如需試用完整功能請)
為了將PPTX幻燈片轉換為JPG,可以簡單地在演示文稿中循環瀏覽幻燈片并將它們另存為JPG文件。以下是執行此操作的步驟。
下面的代碼示例演示如何使用Java將PPTX幻燈片轉換為JPG圖像。
// Load the PowerPoint presentation Presentation pres = new Presentation("presentation.pptx"); // Loop through each slide in the presentation for (ISlide sld : pres.getSlides()) { // Create a full scale image BufferedImage bi = sld.getThumbnail(1f, 1f); // Create a new file File outputfile = new File(sld.getSlideNumber() + "_Slide.jpg"); // Save the image to disk in JPEG format ImageIO.write(bi, "jpg", outputfile); }
PowerPoint PPTX
轉換后的JPG圖像
還可以根據需要自定義尺寸以縮放轉換后的JPG圖像。以下是在PPTX到JPG轉換中指定Scale X和Scale Y值的步驟。
下面的代碼示例演示如何在PPTX中將自定義縮放應用于JPG轉換。
// Load the PowerPoint presentation Presentation pres = new Presentation("presentation.pptx"); // Define dimensions int desiredX = 1200; int desiredY = 800; // Get scaled values of X and Y float ScaleX = (float)(1.0 / pres.getSlideSize().getSize().getWidth()) * desiredX; float ScaleY = (float)(1.0 / pres.getSlideSize().getSize().getHeight()) * desiredY; // Loop through each slide in the presentation for (ISlide sld : pres.getSlides()) { // Create a full scale image BufferedImage bi = sld.getThumbnail(ScaleX, ScaleY); // Create a new file File outputfile = new File(sld.getSlideNumber() + "_Slide.jpg"); // Save the image to disk in JPEG format ImageIO.write(bi, "jpg", outputfile); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn