一 概述
实现原理为将图片放入指定的pdf文件中。
参考文档https://pan.baidu.com/s/11DpS-DOyRrwrYuEIGl7vWw
https://pan.baidu.com/s/11DpS-DOyRrwrYuEIGl7vWw 提取码:yfs2
参考资料:iText 帮助文档.pdf (book118.com)
https://max.book118.com/html/2018/1109/6115022130001230.shtm
二 依赖引入
<!--png to pdf-->
<!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.itextpdf/itext-asian -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
二 实现方式
//生成指定宽高的pdf文件
Document document = new Document(new Rectangle(makeupW, makeupH));
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("PDF文件生成位置");
writer.setPdfVersion(PdfName.P);
document.open();
Image image = Image.getInstance("图片资源位置");
image.setAbsolutePosition(0,0);
//将图片放入pdf文件
document.add(image);
document.close();
图片插入PDF教程:iText实战
本文介绍如何使用iText库将图片插入到PDF文件中,通过创建Document对象、设置尺寸、实例化Image并添加到pdf,实现PDF制作过程。
673

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



