JavaPDF模板⽣成PDF
⼀、 制作PDF模板,使⽤AdobeAcrobat DC,必须使⽤这个来制作from域。使⽤AdobeAcrobat DC将Word导成PDF⽂档进⾏⽂本字段的制作
对模板内容的设置如下:
⼆、将需要动态传⼊模板的值进⾏业务写⼊
主要是写⼊的⽅法
/**
* 根据PDF模板⽣成PDF⽂件
* @param sourceFile 原模板⽂件
品牌护肤品* @param targetFile 动态输⼊写⼊的⽂件
* @param fieldMap 动态数据值
*/
public static void toPDFWriteValue(String sourceFile,String fileName,String targetFilePath,Map<String,Object> fieldMap)throws Exception{
try {
PdfReader reader = new PdfReader(sourceFile)
ByteArrayOutputStream bos = new ByteArrayOutputStream()
PdfStamper ps = new PdfStamper(reader, bos)性病的症状
AcroFields s = ps.getAcroFields()
//解决中⽂
pdf.BaFont bfChine = ateFont("STSong-Light", "UniGB-UCS2-H", fal)
s.addSubstitutionFont(bfChine)手机没网络是什么原因
//判断写⼊⽂件是否存在,不存在创建
File file = new File(targetFilePath)
if (!ists()) {初二拜年
file.mkdirs()
}
String fileSavePath = targetFilePath + fileName
File file1 = new File(fileSavePath)
if (!ists()) {
}
//将值封装⾄map中
for(String key:fieldMap.keySet()){
//遍历赋值
s.tField((key).toString())
}
ps.tFormFlattening(true)
ps.clo()城南旧事沈洁
领导班子工作总结FileOutputStream fos = new FileOutputStream(fileSavePath)
fos.ByteArray())
} catch (FileNotFoundException e) {
工程成本核算<("⽣成PDF⽂件异常", e)
} catch (Exception e) {
<("⽣成PDF⽂件异常", e)
}
英语日期表达
}