java使用Abobe Acrobat DC生成模板
作者:小码66 时间:2022-04-14 21:03:12
一、利用word生成一个文档转成pdf
说明:转换成pdf格式
二、Abobe Acrobat DC图解
利用Abobe Acrobat DC打开pdf
步骤:文件 ---->创建------>创建表单----->选择文件(你转换成pdf文件)
这里是所要增加的文本域、图片域等功能按钮
在你需要的位置增加你说要的功能完成之后进行保存
三、java后台代码
环境maven
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.1.13</version>
<type>pom</type>
</dependency>
生成的模板文件放到适当的位置
所需要生成新的pdf代码
public @ResponseBody Object getFaceVerificationPdf(GzFaceVerification gzFaceVerification, HttpServletRequest request) throws IOException {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
try (PdfDocument document = new PdfDocument(new PdfReader(
new ClassPathResource("static/moban.pdf").getInputStream()), new PdfWriter(outputStream))) {
PdfAcroForm pdfAcroForm = PdfAcroForm.getAcroForm(document, true);
//对图片进行处理(如果不处理在模板中显示不出图片)
PdfFormField pdfFormField = pdfAcroForm.getField("frontIdCardUrl");
InputStream is = new FileInputStream(new File(gzFaceVerification.getFrontIdCardUrl()));
String str = Base64.encodeBytes(StreamUtil.inputStreamToArray(is));
pdfFormField.setValue(str);
pdfAcroForm.addField(pdfFormField);
PdfFormField pdfFormField1 = pdfAcroForm.getField("reverseIdCardUrl");
InputStream is1 = new FileInputStream(new File(gzFaceVerification.getReverseIdCardUrl()));
String str1 = Base64.encodeBytes(StreamUtil.inputStreamToArray(is1));
pdfFormField1.setValue(str1);
pdfAcroForm.addField(pdfFormField1);
PdfFormField pdfFormField2 = pdfAcroForm.getField("photo");
InputStream is2 = new FileInputStream(new File(gzFaceVerification.getPhoto()));
String str2 = Base64.encodeBytes(StreamUtil.inputStreamToArray(is2));
pdfFormField2.setValue(str2);
pdfAcroForm.addField(pdfFormField2);
pdfAcroForm.getField("frontIdCardUrl").setValue(gzFaceVerification.getFrontIdCardUrl());
pdfAcroForm.getField("reverseIdCardUrl").setValue(gzFaceVerification.getReverseIdCardUrl());
pdfAcroForm.getField("photo").setValue(gzFaceVerification.getPhoto());
pdfAcroForm.getField("comparisonResults").setValue(gzFaceVerification.getComparisonResults());
pdfAcroForm.getField("createTime").setValue(gzFaceVerification.getCreateTime());
pdfAcroForm.flattenFields();
}
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_PDF);
httpHeaders.setContentDispositionFormData("attachment", "test.pdf", Charset.forName("UTF-8"));
return ResponseEntity.ok().headers(httpHeaders).body(outputStream.toByteArray());
}
}
来源:https://blog.csdn.net/qq_41971605/article/details/115701174
标签:Java,Abobe,Acrobat,DC,模板
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java关键字final使用方法详解
2023-11-28 22:38:04
在Unity中实现简单的伪时间同步
2023-09-11 03:40:46
用java等语言仿360首页拼音输入全模糊搜索和自动换肤
2022-12-28 18:32:01
![](https://img.aspxhome.com/file/2023/4/74934_0s.jpg)
C# 中如何利用lambda实现委托事件的挂接
2022-02-06 03:18:00
浅谈Silverlight 跨线程的使用详解
2021-10-16 01:23:05
![](https://img.aspxhome.com/file/2023/7/79057_0s.gif)
详解SpringBoot多跨域请求的支持(JSONP)
2023-09-21 04:12:54
![](https://img.aspxhome.com/file/2023/0/74920_0s.png)
Flutter控制组件显示和隐藏三种方式详解
2023-07-07 03:03:30
Qt之调用C#的动态库的解决方法
2023-07-22 03:42:45
![](https://img.aspxhome.com/file/2023/1/67061_0s.png)
WCF如何使用动态代理精简代码架构
2023-09-17 16:25:42
Spring五大类注解读取存储Bean对象的方法
2023-11-09 22:07:07
![](https://img.aspxhome.com/file/2023/3/59003_0s.png)
Java 集合概览(小结)
2023-11-08 02:50:37
![](https://img.aspxhome.com/file/2023/0/59000_0s.jpg)
Java GC 机制与内存分配策略详解
2022-06-12 05:36:44
![](https://img.aspxhome.com/file/2023/6/74926_0s.png)
MyBatis中不建议使用where 1=1原因详解
2021-08-09 23:25:55
![](https://img.aspxhome.com/file/2023/6/79326_0s.jpg)
c#基于WinForm的Socket实现简单的聊天室 IM
2021-11-27 04:47:57
![](https://img.aspxhome.com/file/2023/6/81066_0s.png)
解决Springboot get请求是参数过长的情况
2023-11-27 16:45:37
Java中Optional类及orElse方法详解
2022-07-12 03:21:36
C#中标准的IDispose模式代码详解
2022-03-27 01:40:05
![](https://img.aspxhome.com/file/2023/2/81152_0s.png)
Java数据结构专题解析之栈和队列的实现
2022-11-20 01:24:21
![](https://img.aspxhome.com/file/2023/2/61592_0s.jpg)
彻底解决tomcat中文乱码问题方案
2023-06-25 17:24:46
![](https://img.aspxhome.com/file/2023/1/66201_0s.png)
Spring Boot项目实战之拦截器与过滤器
2022-08-04 15:55:31
![](https://img.aspxhome.com/file/2023/0/72610_0s.png)