java转换ppt,ppt转成图片,获取备注,获取文本 http://yijianfengvip.blog.163.com/blog/static/175273432201152311960
文档展示:POI PPT转图片 http://zhuyufufu.iteye.com/blog/2009799
官方代码: http://poi.apache.org/slideshow/how-to-shapes.html#Render
1 2 3 4 5 6 7 8 9 10 |
<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.15</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-scratchpad</artifactId> <version>3.15</version> </dependency> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
package com.pandy.cms;/** * Created by pandy on 17-3-5. */ import org.apache.poi.hslf.usermodel.HSLFSlide; import org.apache.poi.hslf.usermodel.HSLFSlideShow; import java.awt.*; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.*; /** * 项目名称: idea * 功能说明: * 创建者: Pandy, * 邮箱: panyongzheng@163.com, 1453261799@qq.com * 版权: * 官网: * 创建日期: 17-3-5. * 创建时间: 上午11:24. * 修改历史: * ----------------------------------------------- */ public class PPTtoImage { static String filePath = "D:\\pdf\\转换用.ppt"; static String outputFilePath = "D:\\pdf\\ppt\\"; public static boolean change(File file, File outputFolder) { // TODO 校验输入文件是否存在 以及是否为PPT try { FileInputStream is = new FileInputStream("/home/pandy/桌面/test.ppt"); HSLFSlideShow ppt = new HSLFSlideShow(is); is.close(); Dimension pgsize = ppt.getPageSize(); int idx = 1; for (HSLFSlide slide : ppt.getSlides()) { BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); // clear the drawing area graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height)); // render slide.draw(graphics); // save the output FileOutputStream out = new FileOutputStream("/home/pandy/桌面/temp/test" + idx + ".png"); javax.imageio.ImageIO.write(img, "png", out); out.close(); idx++; } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; } public static void main(String[] args) { File file = new File(PPTtoImage.filePath); File outputFolder = new File(PPTtoImage.outputFilePath); if(!outputFolder.exists()){ outputFolder.mkdirs(); } PPTtoImage.change(file, outputFolder); } } |