使用Apache POI转换的PPT PNG [英] Converting ppt to png using Apache poi
本文介绍了使用Apache POI转换的PPT PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我想使用Apache浦二框架,一个PPT的每张幻灯片转换为单个PNG。问题在于,一些幻灯片是否变形。例如存在这样的情况的背景具有彩虹色到它的滑动。这是对一些幻灯片图像不会出现在所有的.png文件
这里是code:
的FileInputStream是=新的FileInputStream(参数[0]); 幻灯片PPT =新的幻灯片(是);
is.close(); 尺寸PGSIZE = ppt.getPageSize(); 幻灯片[] =滑动ppt.getSlides(); 的for(int i = 0; I< slide.length;我++){ IMG的BufferedImage =新的BufferedImage(pgsize.width,pgsize.height,
BufferedImage.TYPE_INT_RGB);
Graphics2D的图形= img.createGraphics();
//清除绘图区域
graphics.setPaint(Color.white);
graphics.fill(新Rectangle2D.Float(0,0,pgsize.width,pgsize.height)); //渲染
滑动[I] .draw(图形); //保存输出
FileOutputStream中出=新的FileOutputStream(C:\\\\ \\\\用户\\\\法扎德桌面\\\\ slide-+(I + 1)+巴纽);
javax.imageio.ImageIO.write(IMG,PNG,出来);
out.close();
}
解决方案
对于这个工作,我们没有使用:
graphics.setPaint(Color.white);
而是使用:
graphics.setPaint(
slideShow.getSlides()[0] .getBackground()。getFill()。getForegroundColor()
);
Hello I am trying to use the Apache Poi framework to convert each slide of a ppt to an individual png. The problem is that some slides are deformed. For instance there is a slide where the background has a rainbow color to it. And Images that are on some slides do not appear at all on the .png file
here is the code:
FileInputStream is = new FileInputStream(args[0]);
SlideShow ppt = new SlideShow(is);
is.close();
Dimension pgsize = ppt.getPageSize();
Slide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height,
BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
//clear the drawing area
graphics.setPaint(Color.white);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
//render
slide[i].draw(graphics);
//save the output
FileOutputStream out = new FileOutputStream("C:\\Users\\Farzad\\Desktop\\slide-" + (i+1) + ".png");
javax.imageio.ImageIO.write(img, "png", out);
out.close();
}
解决方案
For this to work we don't have to use:
graphics.setPaint(Color.white);
Instead use :
graphics.setPaint(
slideShow.getSlides()[0].getBackground().getFill().getForegroundColor()
);
这篇关于使用Apache POI转换的PPT PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文