问题描述
因此,我在Itext5中使用了代码来将PPT中的每张幻灯片作为图像添加到PDF。
我发现升级代码后不再编译。 这是我从PowerPoint获取图像的方法,如何将这些图像作为页面添加到pdf?我正在将每张幻灯片转换为缓冲的图像并使用Graphics2D进行绘制。
public void convertPptToPdf(Double scaling,float compression) throws Exception {
String path = "myfile" + scaling + "-compression" + compression + "-";
long startTime = System.nanoTime();
ClassLoader classLoader = getClass().getClassLoader();
File theDir =
new File("myfile" + scaling + "-compression" + compression + "/");
theDir.mkdirs();
File file = new File(classLoader.getResource("myfile.ppt").getFile());
FileInputStream is = new FileInputStream(file);
HSLFSlideShow ppt = new HSLFSlideShow(is);
is.close();
Dimension pgsize = ppt.getPageSize();
Double scaledPageSizeHeightDouble = pgsize.height * scaling;
Double scaledPageSizeWidthDouble = pgsize.width * scaling;
Image slideImage = null;
// convert to images
int idx = 1;
for (HSLFSlide slide : ppt.getSlides()) {
BufferedImage img =
new BufferedImage(
pgsize.width * scaling.intValue(),pgsize.height * scaling.intValue(),BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
// these settings make it higher quality
// without it text is very hard to read
graphics.setRenderingHint(
RenderingHints.KEY_ALPHA_INTERPOLATION,RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(
RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
graphics.setRenderingHint(
RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics.setRenderingHint(
RenderingHints.KEY_FRACTIONALMETRICS,RenderingHints.VALUE_FRACTIONALMETRICS_ON);
// clear the drawing area
graphics.setPaint(Color.white);
graphics.scale(scaling,scaling);
graphics.fill(
new Rectangle2D.Float(
0,scaledPageSizeWidthDouble.floatValue(),scaledPageSizeHeightDouble.floatValue()));
// render
slide.draw(graphics);
idx++;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)