结论:1、iText几乎找不到如何PDF转图片的信息,但能找到获取到PDF里面的图片并保存下来的信息;2、PDF box满大街都是参考代码(下面会附上一个作为参考);3、收费的库使用起来更简单,但就是要收费,比如spire.pdf库,土豪可参考使用。
PDF box参考代码:
1、引用库:
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>X.X.XX</version>
</dependency>
2、PDF转图片并写到word里面去:
NiceXWPFDocument document = new NiceXWPFDocument();
PDDocument pdfDoc = PDDocument.load(new File(pdfFilePath));
PDFRenderer pdfRenderer = new PDFRenderer(pdfDoc);
for (int pageIndex = 0; pageIndex < pdfDoc.getNumberOfPages(); ++pageIndex) {
BufferedImage image = pdfRenderer.renderImageWithDPI(pageIndex, 300);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
baos.flush();
XWPFParagraph provincialInfoPic = document.createParagraph();
XWPFRun provincialInfoPicRun = provincialInfoPic.createRun();
provincialInfoPicRun.addPicture(new ByteArrayInputStream(baos.toByteArray()), Document.PICTURE_TYPE_PNG, "", Units.toEMU(400),Units.toEMU(600));
}
本文探讨了在IT领域中,如何使用iText和PDFbox进行PDF转图片操作,指出PDFbox提供了丰富的参考代码,而收费库如spire.pdf则简化了使用过程。作者还展示了PDFbox的PDF转PNG示例代码,并推荐土豪用户考虑付费库。
897

被折叠的 条评论
为什么被折叠?



