长春做网站要多少钱,淘宝客可道cms网站建设,红色页面网站,wordpress 高亮作者留言结论#xff1a;1、iText几乎找不到如何PDF转图片的信息#xff0c;但能找到获取到PDF里面的图片并保存下来的信息#xff1b;2、PDF box满大街都是参考代码#xff08;下面会附上一个作为参考#xff09;#xff1b;3、收费的库使用起来更简单#xff0c;但就是要收费1、iText几乎找不到如何PDF转图片的信息但能找到获取到PDF里面的图片并保存下来的信息2、PDF box满大街都是参考代码下面会附上一个作为参考3、收费的库使用起来更简单但就是要收费比如spire.pdf库土豪可参考使用。
PDF box参考代码
1、引用库
dependencygroupIdorg.apache.pdfbox/groupIdartifactIdpdfbox/artifactIdversionX.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));
}