一、利用word生成一个文档转成pdf
说明:转换成pdf格式
二、abobe acrobat dc图解
利用abobe acrobat dc打开pdf
步骤:文件 ---->创建------>创建表单----->选择文件(你转换成pdf文件)
这里是所要增加的文本域、图片域等功能按钮
在你需要的位置增加你说要的功能完成之后进行保存
三、java后台代码
环境maven
1
2
3
4
5
6
|
<dependency>
<groupid>com.itextpdf</groupid>
<artifactid>itext7-core</artifactid>
<version> 7.1 . 13 </version>
<type>pom</type>
</dependency>
|
生成的模板文件放到适当的位置
所需要生成新的pdf代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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生成模板的文章就介绍到这了,更多相关abobe acrobat dc生成模板内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/qq_41971605/article/details/115701174