//根据模板下载模板
/**
*
* 政策5-8条的创建的pdf的模板
*/
public String createPdfCashTemplate(PdfCashParam pdfCashParam) throws Exception{
String templatePath = pdfCashParam.getFilePath()+"/"+"CashTemplate.pdf";
String newPDFPath = pdfCashParam.getFilePath()+"/"+ pdfCashParam.getCashCode()+"/"+pdfCashParam.getTitle()+".pdf";
PdfReader reader;
FileOutputStream out;
ByteArrayOutputStream bos;
PdfStamper stamper;
try{
out = new FileOutputStream(newPDFPath);//输出流
reader = new PdfReader(templatePath);//读取pdf模板
bos = new ByteArrayOutputStream();
stamper = new PdfStamper(reader, bos);
AcroFields form = stamper.getAcroFields();
//form.getField("policyInfo");
form.setField("title",pdfCashParam.getTitle());
form.setField("filed_1",pdfCashParam.getCompanyName());
form.setField("filed_2",pdfCashParam.getInstCode());
form.setField("filed_3",pdfCashParam.getApplyAmt());
form.setField("filed_4",pdfCashParam.getLinkMan());
form.setField("filed_5",pdfCashParam.getLinkWay());
form.setField("filed_6",pdfCashParam.getPoliceName());
form.setField("filed_7",pdfCashParam.getCashCode());
form.setField("filed_8",pdfCashParam.getCashDate());
form.setField("filed_9",pdfCashParam.getCompanyName());
form.setField("filed_10",pdfCashParam.getCompanyBank());
form.setField("filed_11",pdfCashParam.getKhBankZh());
form.setField("filed_12",pdfCashParam.getKhJoinbankNo());
form.setField("filed_13",pdfCashParam.getCompanyAccount());
form.setField("filed_14",pdfCashParam.getKhProvince()+" - "+pdfCashParam.getKhCity());
form.setField("filed_15",pdfCashParam.getPoliceInfo());
form.setField("filed_16",pdfCashParam.getBaseInfo());
form.setField("filed_17",pdfCashParam.getMaterial());
stamper.setFormFlattening(true);
stamper.close();
Document doc = new Document();
PdfCopy copy = new PdfCopy(doc, out);
doc.open();
PdfImportedPage importPage = copy.getImportedPage(
new PdfReader(bos.toByteArray()), 1);
copy.addPage(importPage);
doc.close();
}catch (Exception e){
e.printStackTrace();
logger.error("生成pdf模板错误:",e.getMessage());
}
return newPDFPath;
}