Java通过PDF模板导出数据,adobeacrobat的PDF编辑器,itextpdf

更新时间:2023-07-31 07:19:38 阅读: 评论:0

Java通过PDF模板导出数据,adobeacrobat的PDF编辑器,itextpdf
前⾔
之前做过⼀个项⽬,通过PDF上的占位符动态地填充数据并下载,这⾥就需要⽤到adobe的软件去设置PDF的格式,并获取到当前占位符的id。
小学数学电子课本环境
adobe acrobat :pdf 编辑器;
使⽤ word导出PDF格式
打 开 adobe acrobat ⼯具;(如果提⽰错误,右键选择以管理员⽅式运⾏试试)
选择 ⽂件 -> 创建 -> 创建表单
选择刚保存的pdf⽂件,并打开;
adobe acrobat ⼯具会在表格中⾃动填充⼀些“⽂本域”,默认 “fill_” 开头;
看到有 12 个 ⽂本域,就说明模板创建成功了,直接 ctrl+s 保存下,关闭即可;
太极二章itext.jar : pdf 开发组件
<!--itextpdf jar包开始-->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.6</version>
</dependency>
<dependency>
<groupId>l</groupId>
<artifactId>xmlworker</artifactId>
<version>5.5.6</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
苏州水乡
<version>5.2.0</version>
</dependency>
java开发
未来的机器人作文
@RequestMapping(value ="/downloadWord/{employeeId}", method = RequestMethod.GET)
public Result downloadWord(HttpServletRespon respon,@PathVariable Long employeeId){
final BaAccount dbBa = (employeeId).getResultData();
Date signDate = AuditTime();
悖谬
Picture sign = Sign();
final String sysPath =getSispPath().replaceAll("/sharedSalaryManager/","");
Map<String, String> params =new HashMap<String, String>(){
{
put("urname", Name());
put("firstPartySignDate",isNotNull(signDate)? ISO_DATE_FORMAT.format(signDate):"_____________");
put("condPartySignDate",isNotNull(signDate)? ISO_DATE_FORMAT.format(signDate):"_____________");
put("sign",isNotNull(sign)? sysPath + RemoteRelativeUrl():"");
}
};
学前儿童健康教育
portTempPDF(respon, params,"personAndPlatform.pdf",380.00f,360.00f);
}
public static Result exportTempPDF(HttpServletRespon respon, Map<String, String> map, String templateName,float absoluteX,float absoluteY){ // 模板路径
String inRelativePath =getSispPath()+"WEB-INF/word/";
String inAbsolutePath = inRelativePath + templateName;
String inAbsolutePath = inRelativePath + templateName;
ByteArrayOutputStream bos = null;
PdfStamper ps = null;
try{
PdfReader reader =new PdfReader(inAbsolutePath);
bos =new ByteArrayOutputStream();
Font font = Font(getSispPath()+"WEB-INF/fonts/STSONG.TTF", BaFont.IDENTITY_H, BaFont.EMBEDDED);
BaFont baFont = BaFont();
ps =new PdfStamper(reader, bos);
AcroFields form = ps.getAcroFields();
form.addSubstitutionFont(baFont);
for(Map.Entry<String, String> entry : Set()){
String key = Key();
String value = Value();泌乳素高的原因
ains("/")&&countMatches(value,"/")>=2){
String imgPath = (Key());
int pageNo = FieldPositions(key).get(0).page;
Image image = Instance(imgPath);
PdfContentByte under = ps.getOverContent(pageNo);
image.scaleToFit(100,40);
image.tAbsolutePosition(absoluteX, absoluteY);
image.tInverted(fal);
弥月
under.addImage(image);
}el{
form.tField(key, value);
}
}
ps.tFormFlattening(true);
String fileName1 = de(templateName.substring(0, templateName.indexOf("."))+ DateUtil.ISO_DATETIME_FORMAT_NONE.form at(new Date())+".pdf","UTF-8");
String headStr ="attachment; filename=\""+ fileName1 +"\"";
respon.tContentType("APPLICATION/OCTET-STREAM");
respon.tHeader("Content-Disposition", headStr);
OutputStream out = OutputStream();
out.ByteArray());
out.clo();
return ResultUtil.buildSuccess();
}catch(Exception e){
throw new GeneralBizException("模板PDF填充导出异常,请联系管理员:"+ e.getMessage());
}finally{
try{
if(isNotNull(ps)){
ps.clo();
}
if(isNotNull(bos)){
bos.clo();
}
}catch(Exception e){
e.printStackTrace();
}
}
}

本文发布于:2023-07-31 07:19:38,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1102845.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:模板   填充   导出   选择   数据   格式
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图