使用Apache POI将PPT转换为PNG

编程入门 行业动态 更新时间:2024-10-10 07:22:52
本文介绍了使用Apache POI将PPT转换为PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

按照 poi.apache/提供的示例进行操作slideshow/how-to-shapes.html 我可以进行转换了.

By following the example provided at poi.apache/slideshow/how-to-shapes.html i got the conversion to work.

FileInputStream is = new FileInputStream("slideshow.ppt"); SlideShow ppt = new SlideShow(is); is.close(); Dimension pgsize = ppt.getPageSize(); Slide[] slide = ppt.getSlides(); for (int i = 0; i < slide.length; i++){ BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height)); slide[i].draw(graphics); FileOutputStream out = new FileOutputStream("slide-" + (i+1) + ".png"); javax.imageio.ImageIO.write(img, "png", out); out.close(); }

但是,生成的图像非常小. 如何增加图像输出的大小?

However the generated images are very small. How do increase the size of the image output?

推荐答案

您需要调整图形上下文的大小并添加常规转换.

You need to resize the graphics context and add a general transformation.

FileInputStream is = new FileInputStream("slideshow.pptx"); SlideShow ppt = new SlideShow(is); is.close(); double zoom = 2; // magnify it by 2 AffineTransform at = new AffineTransform(); at.setToScale(zoom, zoom); Dimension pgsize = ppt.getPageSize(); Slide[] slide = ppt.getSlides(); for (int i = 0; i < slide.length; i++) { BufferedImage img = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); graphics.setTransform(at); graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height)); slide[i].draw(graphics); FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png"); javax.imageio.ImageIO.write(img, "png", out); out.close(); }

更多推荐

使用Apache POI将PPT转换为PNG

本文发布于:2023-10-31 10:37:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545831.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   POI   Apache   PNG   PPT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!