MS PowerPoint演示文稿不能直接从Web或桌面应用程序中显示。一种可能的解决方案是将PPTX演示文稿中的幻灯片转换为JPEG或PNG等图像。
>>你可以点击这里下载Aspose.Slides for Java v20.10测试体验。(安装包仅提供部分功能,并设置限制,如需试用完整功能请申请免费授权)
- 使用Java将PPTX转换为JPG图像
- 在PPTX到JPG转换中自定义图像尺寸
软件国产化服务季来啦!整合所有格式的Aspose.Total永久授权正在火热促销中,乐享85折起!联系客服立马1分钟了解全部咨询!
PPTX到JPG Java的转换
为了将PPTX幻灯片转换为JPG,可以简单地在演示文稿中循环浏览幻灯片并将它们另存为JPG文件。以下是执行此操作的步骤。
- 使用Presentation类加载PowerPoint PPTX文件。
- 使用Presentation.getSlides()方法检索演示文稿中的幻灯片。
- 使用ISlide界面访问每张幻灯片。
- 使用ISlide.getThumbnail(1f,1f)方法将幻灯片的缩略图获取到BufferedImage对象中。
- 将BufferedImage另存为JPG文件。
下面的代码示例演示如何使用Java将PPTX幻灯片转换为JPG图像。
// Load the PowerPoint presentationPresentation pres = new Presentation("presentation.pptx");// Loop through each slide in the presentationfor (ISlide sld : pres.getSlides()) {// Create a full scale imageBufferedImage bi = sld.getThumbnail(1f, 1f);// Create a new fileFile outputfile = new File(sld.getSlideNumber() + "_Slide.jpg");// Save the image to disk in JPEG formatImageIO.write(bi, "jpg", outputfile);}
PowerPoint PPTX
转换后的JPG图像
PPTX到JPG –自定义图像尺寸
还可以根据需要自定义尺寸以缩放转换后的JPG图像。以下是在PPTX到JPG转换中指定Scale X和Scale Y值的步骤。
- 使用Presentation类加载PowerPoint PPTX文件。
- 分别使用幻灯片的宽度和高度指定x轴和y轴的缩放比例值。
- 使用Presentation.getSlides()方法检索演示文稿中的幻灯片。
- 使用ISlide界面访问每张幻灯片。
- 使用ISlide.getThumbnail(ScaleX,ScaleY)方法将幻灯片的缩略图获取到BufferedImage对象中。
- 将BufferedImage另存为JPG文件。
下面的代码示例演示如何在PPTX中将自定义缩放应用于JPG转换。
// Load the PowerPoint presentationPresentation pres = new Presentation("presentation.pptx");// Define dimensionsint desiredX = 1200;int desiredY = 800;// Get scaled values of X and Yfloat 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 presentationfor (ISlide sld : pres.getSlides()) {// Create a full scale imageBufferedImage bi = sld.getThumbnail(ScaleX, ScaleY);// Create a new fileFile outputfile = new File(sld.getSlideNumber() + "_Slide.jpg");// Save the image to disk in JPEG formatImageIO.write(bi, "jpg", outputfile);}
还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!