java后台,利用Abobe Acrobat DC生成模板生成表单动态pdf

1.利用word生成一个文档转成pdf

word模板
说明:转换成pdf格式

1.Abobe Acrobat DC图解

利用Abobe Acrobat DC打开pdf
步骤:文件 ---->创建------>创建表单----->选择文件(你转换成pdf文件)
图解
这里是所要增加的文本域、图片域等功能按钮
在这里插入图片描述
在你需要的位置增加你说要的功能完成之后进行保存
在这里插入图片描述

3.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());
        }
    }
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值