我需要将 docx 文件逐页转换为图像。因此,如果我将页码传递给一个方法 - 该方法应该从 docx 文件中读取该页面并将其转换为图像。任何使用 Apache POI API 的例子?我为 pptx 文件执行了此操作,但无法为 docx 找到类似的方法。以下是 pptx 的代码。
FileInputStream is = new FileInputStream(strTempPath);
XMLSlideShow pptx = new XMLSlideShow(is);
is.close();
double zoom = 2; // magnify it by 2
AffineTransform at = new AffineTransform();
at.setToScale(zoom, zoom);
Dimension pgsize = pptx.getPageSize();
XSLFSlide[] slide = pptx.getSlides();
}
// BufferedImage img = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_INT_RGB);
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, 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[iPageNo].draw(graphics);
// FileOutputStream output = new ByteArrayOutputStream("C:/Temp/aspose/word/slide-" + (10 + 1) + ".png");
output = new ByteArrayOutputStream();
javax.imageio.ImageIO.write(img, "png", output);