利用POI将PPT转成图片

  1. 下载POI:http://poi.apache.org/download.html
  2. 导入poi.jar与poi-scratchpad.jar(后边的这个必须导,不然没有HSLF这个包)
SlideShow slideShow = new SlideShow(hslfSlideShow);
if(slideShow.getSlides()!=null&&slideShow.getSlides().length>0){
	Slide slide = slideShow.getSlides()[0];//读取第一页
	TextRun[] textRuns = slide.getTextRuns();
	for (TextRun textRun : textRuns) {
		for (RichTextRun richTextRun  : textRun.getRichTextRuns()) {
			richTextRun.setFontName("宋体");//防止中文乱码
		}
	}
	BufferedImage img = new BufferedImage(
		slideShow.getPageSize().width,
		slideShow.getPageSize().height,
		BufferedImage.TYPE_INT_RGB);   
	Graphics2D graphics = img.createGraphics();
	slide.draw(graphics);
	FileOutputStream fos = new FileOutputStream("d:/p1.png");
	ImageIO.write(img, "png", fos);
	fos.close();
}

 

发表回复

您的电子邮箱地址不会被公开。