根据现有PDF模板填充信息(SpringBoot)
2024-10-19 16:26:14
根据现有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;
}
搞定收工。。。。
最新文章
- GridLayout 使用
- Android定时器,推荐ScheduledThreadPoolExecutor
- gpload的简单实用
- Java中的enum
- CSU	1639 队长,我想进集训队!
- java排序算法(十):桶式排序
- OpenResty 在又拍云容器平台中的应用
- 交叉编译 tcpdump
- LeetCode 104. Maximum Depth of Binary Tree二叉树的最大深度 C++/Java
- SQL: Cannot create JDBC driver of class &#39;&#39; for connect URL
- 更新 Anaconda 库文件
- vue组件传值
- python成长之路六-函数的初识
- 异构无线网络之QOS简介
- Mysql 性能优化5【重要】数据库结构优化
- [HAOI2008]移动玩具(状压&;带权二分图)
- Adobe Acrobat Reader DC For Android 下载
- 【转】Phong和Blinn-Phong光照模型
- Html.DropDownList传值
- Linux内核多线程实现方法 —— kthread_create函数【转】
热门文章
- bootstraptable为行中的按钮添加事件
- WdatePicker.js的使用方法 帮助文档 使用说明(时间控件)
- How to use mouse to moving windows of not have title bar?
- Rotate image and fit show use canvas
- [DT] 数据结构术语中英文对照
- Hdu4280 Island Transport 2017-02-15 17:10 44人阅读 评论(0) 收藏
- 用shell脚本 计算两个数的加减乘除取余
- 18-11-1 Scrum Meeting 4
- java和json互转
- StringFormate使用