需求
有一个存在的PDF 文件,想往该PDF 文件中指定位置插入文本内容,下面我们开始使用Itext 来实现
编码实现
依赖
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.12</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>1.0</version>
</dependency>
代码实现
@Test
public void addContent() throws IOException, DocumentException {
String filePath = "C:\\Users\\fan\\Desktop\\测试模板变量_多页.pdf";
String savePath = "C:\\Users\\fan\\Desktop\\测试模板变量6.pdf";