• Java导出pdf文件数据


     提示:导出pdf文件,需要3个jar包iText-2.1.5.jar,iTextAsian.jar,iText-rtf-2.1.4.jar。

    public boolean outputPdfJhsy(EntityBean data) { try { Global.getInstance().LogApp("导出pdf开始"); String pdfpath = File.get("LEAP/NSESTModule/WRModule/nsjhsyzm.pdf").getAbsolutePath(); //从eclipse文件夹中得到pdf模版路径 String imgpath = File.get("LEAP/NSESTModule/WRModule/image/weiji.gif").getAbsolutePath(); //右下角盖章图片 PdfReader reader = new PdfReader(pdfpath); //创建输出目录 String pdfSavePath = NameedPathUtil.getPath("default")+"nsestpdf/"; File.get(pdfSavePath).mkdir(); String filename = Global.getInstance().GetUUID()+".pdf"; pdfSavePath = pdfSavePath+filename; PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(pdfSavePath)); // 拿到第一页的上部内容部分 PdfContentByte over = stamp.getOverContent(1); //获取表单域(用Adobe Acrobat Pro工具) AcroFields form = stamp.getAcroFields(); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日"); EntityBean bean = data; try { form.setField("busino", bean.getString("busino")); form.setField("jsbm", bean.getString("jsbm")); form.setField("wname",bean.getString("wname")); form.setField("wsfz",bean.getString("wsfz")); form.setField("mname",bean.getString("mname")); form.setField("msfz",bean.getString("msfz")); form.setField("whjd",bean.getString("whjd")); form.setField("wxjzd",bean.getString("wxjzd")); form.setField("hyzk",bean.getString("hyzk")); form.setField("jsqk",bean.getString("jsqk")); form.setField("zncount",bean.getString("zncount")); form.setField("znqk",bean.getString("znqk")); form.setField("slrq",sdf2.format( sdf.parse(bean.getString("slrq")) ) ); form.setField("wfjhsyzc",bean.getString("wfjhsyzc")); form.setField("qtsm",bean.getString("qtsm")); form.setField("wname2",bean.getString("wname2")); form.setField("wsfz2",bean.getString("wsfz2")); form.setField("zmlxname", bean.getString("zmlxname")); form.setField("jbr",bean.getString("jbr")); form.setField("lxdh",bean.getString("lxdh")); form.setField("sprq",bean.getString("sprq")); } catch (Exception e) { Global.getInstance().LogApp("插入pdf表单域异常"); e.printStackTrace(); } stamp.setFormFlattening(true); // 这句不能少 //创建一个image对象 Image image = Image.getInstance(imgpath); //设置image对象的输出位置pa.getAsNumber(pa.size()-1).floatValue() 是该页pdf坐标轴的y轴的最大值 image.setAbsolutePosition(398,170); image.scalePercent(70); over.addImage(image); over.stroke(); stamp.close(); Global.getInstance().LogApp("导出pdf结束"); } catch (FileNotFoundException e) { Global.getInstance().LogApp("异常1"); e.printStackTrace(); return false; } catch (DocumentException e) { Global.getInstance().LogApp("异常2"); e.printStackTrace(); return false; } catch (IOException e) { Global.getInstance().LogApp("异常3"); e.printStackTrace(); return false; } finally { } return true; }
  • 相关阅读:
    删除功能ThinkPHP
    详解又详解KMP中的next和nextval的算法
    Thinphp ajax搜索框实施搜索提示
    tp3无法select一条数据记录
    一步步学习springcloud之总览(一)
    使用github搭建自己的maven仓库
    Win7 安装7zip后无7zip右键菜单的解决办法
    基于微信的邮箱新邮件推送
    Apache James 使用MySQL存储启动报错Specified key was too long; max key length is 3072 bytes
    错误提示:Error running MainActivity: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.
  • 原文地址:https://www.cnblogs.com/zhaojinhui/p/3998355.html
Copyright © 2020-2023  润新知