根据现有PDF模板填充信息(SpringBoot+maven)

首先得有一个pdf模板,建立pdf模板需要下载工具
红色框为文本框,filename为域名。java需要根据域名赋值

pom 文件配置

<!-- always needed -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>7.0.3</version>
</dependency> <!-- only needed for forms -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>forms</artifactId>
<version>7.0.3</version>
</dependency> <!-- only needed for Asian fonts -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>font-asian</artifactId>
<version>7.0.3</version>
</dependency>

java 代码

 // pdf文件
private Boolean tranPdf(CopyRightsVo copyRightsVo) {
// 模板地址
String filePath = UlegalZCUtil.rootPath() + File.separator + "pdf" + File.separator + "templateC.pdf";
// 填完信息后生成新的模板地址
String toPath = UlegalZCUtil.rootPath() + File.separator + "pdf" + File.separator + "templateOL" + ".pdf";
try {
System.out.println(filePath);
PdfDocument pdfDoc = new PdfDocument(new PdfReader(filePath), new PdfWriter(toPath));
PdfAcroForm pdfAcroForm = PdfAcroForm.getAcroForm(pdfDoc, true);
pdfAcroForm.getField("fileName").setValue("小编");
pdfAcroForm.getField("applicant").setValue("ol");
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
String cmmitTime = simpleDateFormat.format(date);
pdfAcroForm.getField("time").setValue(cmmitTime);
// pdfAcroForm.getField("hashValue").setValue(copyRightsVo.getHashValue());
pdfAcroForm.flattenFields();
pdfDoc.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}

搞定收工。。。。

最新文章

  1. GridLayout 使用
  2. Android定时器,推荐ScheduledThreadPoolExecutor
  3. gpload的简单实用
  4. Java中的enum
  5. CSU 1639 队长,我想进集训队!
  6. java排序算法(十):桶式排序
  7. OpenResty 在又拍云容器平台中的应用
  8. 交叉编译 tcpdump
  9. LeetCode 104. Maximum Depth of Binary Tree二叉树的最大深度 C++/Java
  10. SQL: Cannot create JDBC driver of class &#39;&#39; for connect URL
  11. 更新 Anaconda 库文件
  12. vue组件传值
  13. python成长之路六-函数的初识
  14. 异构无线网络之QOS简介
  15. Mysql 性能优化5【重要】数据库结构优化
  16. [HAOI2008]移动玩具(状压&amp;带权二分图)
  17. Adobe Acrobat Reader DC For Android 下载
  18. 【转】Phong和Blinn-Phong光照模型
  19. Html.DropDownList传值
  20. Linux内核多线程实现方法 —— kthread_create函数【转】

热门文章

  1. bootstraptable为行中的按钮添加事件
  2. WdatePicker.js的使用方法 帮助文档 使用说明(时间控件)
  3. How to use mouse to moving windows of not have title bar?
  4. Rotate image and fit show use canvas
  5. [DT] 数据结构术语中英文对照
  6. Hdu4280 Island Transport 2017-02-15 17:10 44人阅读 评论(0) 收藏
  7. 用shell脚本 计算两个数的加减乘除取余
  8. 18-11-1 Scrum Meeting 4
  9. java和json互转
  10. StringFormate使用