温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

java如何使用Abobe Acrobat DC生成模板

发布时间:2021-05-07 11:09:56 来源:亿速云 阅读:225 作者:小新 栏目:开发技术

这篇文章给大家分享的是有关java如何使用Abobe Acrobat DC生成模板的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

Java有哪些集合类

Java中的集合主要分为四类:1、List列表:有序的,可重复的;2、Queue队列:有序,可重复的;3、Set集合:不可重复;4、Map映射:无序,键唯一,值不唯一。

一、利用word生成一个文档转成pdf

java如何使用Abobe Acrobat DC生成模板

说明:转换成pdf格式

二、Abobe Acrobat DC图解

利用Abobe Acrobat DC打开pdf

步骤:文件 ---->创建------>创建表单----->选择文件(你转换成pdf文件)

这里是所要增加的文本域、图片域等功能按钮

java如何使用Abobe Acrobat DC生成模板

在你需要的位置增加你说要的功能完成之后进行保存

java如何使用Abobe Acrobat DC生成模板

三、java后台代码

环境maven

<dependency>
			<groupId>com.itextpdf</groupId>
			<artifactId>itext7-core</artifactId>
			<version>7.1.13</version>
			<type>pom</type>
		</dependency>

生成的模板文件放到适当的位置

java如何使用Abobe Acrobat DC生成模板

所需要生成新的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());
        }
    }

感谢各位的阅读!关于“java如何使用Abobe Acrobat DC生成模板”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI