java使用Abobe Acrobat DC生成模板
作者:小码66 发布时间:2022-04-14 21:03:12
标签:Java,Abobe,Acrobat,DC,模板
一、利用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


猜你喜欢
- 前言前段时间因为工作的需要用到Spring事件,翻翻文档将功能实现了,但是存在少许理解不畅的地方,今天有空来梳理梳理。需求背景叶子同学在新入
- 本文将介绍使用Spring Boot集成Mybatis并实现主从库分离的实现(同样适用于多数据源)。延续之前的Spring Boot 集成M
- 一、C#对XML格式数据的解析1、用XMLDocument来解析XmlDocument xmlDocument = new XmlDocum
- 当一个结合中想根据某一个字段做去重方法时使用以下代码IQueryable 继承自IEnumerable先举例:#region linq to
- 本文实例为大家分享了C#实现俄罗斯方块的具体代码,供大家参考,具体内容如下1.调色板代码namespace Tetris{ class Pa
- springboot启动失败的问题springboot版本是1.3.0.M1,连接的mysql版本为8,用spring-boot-start
- 利用mybtis插件打印完整的sql,将占位符?替换成实际值import org.apache.ibatis.cache.CacheKey;
- 对于一些特殊的情况,split拆分后并没有保留全的元素如下例子:String x ="a,,,,,,";String [
- 项目比较大有时候会比较卡,虽然有GC自动清理机制,但是还是有不尽人意的地方。所以尝试在项目启动文件中,手动写了一个定时器,定时清理内存,加快
- 一. this关键字1. 简介我们知道,this是”这个“的意思。在java中表示当前类的对象, 可
- 目录一、抽象类1.抽象类概述1.1 为什么要有抽象类?(抽象类的作用)1.2 抽象类的定义2. 抽象类特点3.抽象类成员特点4.抽象类案例二
- 一、前言在日常工作中,如果涉及到与第三方进行接口对接,有的会使用WebService的方式,这篇文章主要讲解在.NET Framework中
- 网上的解决方法:这个是从网上看来的file-->setting-->plugins,搜索tomcat然后install之后会提示
- 输入一个数组,然后颠倒次序进行输出,这种算法在程序开发
- 效果图,每隔1秒,变换一下时间 xml: <RelativeLayout xmlns:android="http
- CSV(Comma Separated Values)文件是一种纯文本文件,包含用逗号分隔的数据,常用于将数据从一个应用程序导入或导出到另一
- 一、概述应用程序配置文件,对于asp.net是 web.config,对于WINFORM程序是 App.Config(ExeName.exe
- 本文实例讲述了Android开发圆角Button按钮实现过程,分享给大家供大家参考,具体内容如下需求及效果图:实现思路:1、shape实现圆
- protected void Page_Load(object sender, EventArgs e) { &nb
- 前言虽然Aandroid目前已经有RecyclerView了、非常强大的一个View、可以直接控制成ListView以及GridView等、