1.使用工具编辑好PDF模板
本人使用的是(Adobe Acrobat DC),添加域,生成如下模板:
2.实现PDF导出
2.1导入itex相关包
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
2.1导出PDF
// pdf模板
String fileName = "D:/表1进度付款申请单.pdf";
//读取pdf
PdfReader reader = new PdfReader(fileName);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
//将要生成的目标PDF文件名称
PdfStamper ps = new PdfStamper(reader, bos);
//PdfContentByte under = ps.getUnderContent(1);
//设置中文字体
BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
//取出报表模板中的所有字段
AcroFields fields = ps.getAcroFields();
field