zoukankan      html  css  js  c++  java
  • pdf 使用模板下载

      //根据模板下载模板

    /**
    *
    * 政策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;
    }
  • 相关阅读:
    测试开发知识体系
    渗透测试全套教程(从原理到实战)
    解决edittext输入多行可以滑动的问题
    SharedPreferences实现自动登录记住用户名密码
    listview当选中某一个item时设置背景色其他的不变
    转 -android:程序无响应,你该如何定位问题?
    区分listview的item和Button的点击事件
    转--2014年最新810多套android源码2.46GB免费一次性打包下载
    转-android 支付宝SDK集成
    转-封装网络请求库,统一处理通用异常 (基于volley网络请求库)
  • 原文地址:https://www.cnblogs.com/chengyangyang/p/9947880.html
Copyright © 2011-2022 走看看