pom依赖
<dependency> <groupId>com.itextpdf</groupId> <artifactId>itext7-core</artifactId> <version>7.0.2</version> <type>pom</type> </dependency> public static void createTempPdf(String filePath,String image){ try { PdfWriter writer = new PdfWriter(new FileOutputStream(new File(filePath))); PdfDocument pdf = new PdfDocument(writer); Document document = new Document(pdf); PdfFont font = PdfFontFactory.createFont("STSongStd-Light", "UniGB-UCS2-H", false); Paragraph title = new Paragraph("标题") .setTextAlignment(TextAlignment.CENTER) .setFontSize(16); title.setFont(font); document.add(title); document.add(new Paragraph("模板内容").setFont(font)); Image codeQrImage = new Image(ImageDataFactory.create("F:/"+image),450,600); //图片大小 codeQrImage.scaleAbsolute(70, 30); document.add(codeQrImage); document.close(); writer.close(); pdf.close(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { createTempPdf("F:/"+"名称.pdf","a.jpg"); }我是存在f盘了 ,根据个人需求存储到相应位置就好
参考博客:https://blog.csdn.net/weixin_30243533/article/details/95257015?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase https://blog.csdn.net/weixin_38345306/article/details/85929589 希望能对大家有所帮助
