我用POI提供的方法去转换ppt内容为图片时,出错了,具体代码如下:
public static void main(String[] args) throws FileNotFoundException,
IOException {
final String PPT_TEMPLATE = "data/test.pptx";
float scale = 1;
XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(PPT_TEMPLATE));
Dimension pgsize = ppt.getPageSize();
int width = (int) (pgsize.width * scale);
int height = (int) (pgsize.height * scale);
XSLFSlide slide = ppt.getSlides()[5];
BufferedImage img = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = img.createGraphics();
// default rendering options
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
graphics.setColor(Color.white);
graphics.clearRect(0, 0, width, height);
graphics.scale(scale, scale);
// draw stuff
slide.draw(graphics);
// save the result
FileOutputStream out = new FileOutputStream(new File("D:/test.png"));
try {
ImageIO.write(img, "png", out);
} finally {
out.close();
}
System.out.println("Job Done");
}
这是ppt内容的截图,下面这张是转换后的图片
转换过程中,ppt里面的图表内容丢失了,大神能否帮忙看一下,指导一下?
------解决思路----------------------
是不是原来PPT上就是一个折线图?