首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

应用poi将ppt转成图像文件

2012-09-14 
使用poi将ppt转成图像文件下载POI:http://poi.apache.org/download.html导入poi.jar与poi-scratchpad.jar(

使用poi将ppt转成图像文件

    下载POI:http://poi.apache.org/download.html导入poi.jar与poi-scratchpad.jar(后边的这个必须导,不然没有HSLF这个包)

?

?? ?HSLFSlideShow hslfSlideShow = new HSLFSlideShow("D:/p1.ppt");?? ?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();?? ?}

热点排行