2010-08-12 107 views

回答

1

回答我的問題,我訂閱了開發郵件列表,並問到這個問題。

答案是,這functionailty目前不被Apache POI支持

+0

你應該接受你自己的答案。 – 2011-06-01 18:38:14

0

pptx4j可以幫助你在HTML創建SVG(雖然還有很多工作要做,以支持所有的形狀);然後你可以使用其中一個工具從一個自動瀏覽器窗口創建一個圖像。

3

在它工作的同時(...從there複製它):

import java.awt.Color; 
import java.awt.Dimension; 
import java.awt.Graphics2D; 
import java.awt.geom.AffineTransform; 
import java.awt.geom.Rectangle2D; 
import java.awt.image.BufferedImage; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 

import org.apache.poi.xslf.usermodel.XMLSlideShow; 
import org.apache.poi.xslf.usermodel.XSLFSlide; 

public class PptToPng { 
    public static void main(String[] args) throws Exception { 
     FileInputStream is = new FileInputStream("example.pptx"); 
     XMLSlideShow ppt = new XMLSlideShow(is); 
     is.close(); 

     double zoom = 2; // magnify it by 2 
     AffineTransform at = new AffineTransform(); 
     at.setToScale(zoom, zoom); 

     Dimension pgsize = ppt.getPageSize(); 

     XSLFSlide[] 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(); 
     } 
    } 
} 
相關問題