我正在尝试使用apache poi将pptx转换为png或pdf,但转换后所有图表都将被丢弃。我希望所有图表都在我转换的png或pdf中。
版本:Apache POI 3.16
public void convertPPTXtoImg() throws IOException, DocumentException, InvalidFormatException {
FileInputStream inputStream = new FileInputStream("vzw.pptx");
XMLSlideShow ppt = new XMLSlideShow(OPCPackage.open(inputStream));
inputStream.close();
Dimension pgsize = ppt.getPageSize();
float scale = 1;
int width = (int) (pgsize.width * scale);
int height = (int) (pgsize.height * scale);
int i = 1;
int totalSlides = ppt.getSlides().size();
for (XSLFSlide slide : ppt.getSlides()) {
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));
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);
slide.draw(graphics);
FileOutputStream out = new FileOutputStream("images/"+i+".png");
javax.imageio.ImageIO.write(img, "png", out);
out.close();
i++;
}
}