zoukankan      html  css  js  c++  java
  • pdf 中添加文章操作

        pom.xml添加Jar依赖
            <!-- pdf处理jar依赖 start -->
            <dependency>
                <groupId>com.itextpdf</groupId>
                <artifactId>itextpdf</artifactId>
                <version>5.5.12</version>
            </dependency>
            <!-- pdf处理jar依赖 end -->

            <!-- pdf处理jar包依赖 start -->
            <dependency>
                <groupId>com.itextpdf</groupId>
                <artifactId>itext-asian</artifactId>
                <version>5.2.0</version>
            </dependency>
            <dependency>
                <groupId>com.lowagie</groupId>
                <artifactId>itext</artifactId>
                <version>4.2.1</version>
            </dependency>
            <!-- pdf处理jar包依赖 end -->   


                //pdf模板所在路径 (通过类名获取文件路径)
                String templateFileName = ContractServiceImpl.class.getClassLoader().getResource("sb_loan_contract_borrow.pdf").getFile();
                //使用itext的包读取pdf模板
                PdfReader pdfReader = new PdfReader(templateFileName);
                
                //根据模板到时候会生成一个新的pdf文件,并输出该文件
                //使用工具类获取生成之后的路径
                //creditorRights.getId() + ".pdf"  文件名
                String outPutFileName = SystemConfig.getConfigProperty("contract_output_path") + creditorRights.getId() + ".pdf";
                //(输出)生成文件名字
                FileOutputStream fos = new FileOutputStream(outPutFileName);
                
                PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);
                //这句话的意思是 把你想添加的内容压进去,填进去  不能少
                pdfStamper.setFormFlattening(true);
                
                //设置pdf模板中的表单输入域,将表单输入域填上数据
                pdfStamper.getAcroFields().setField("protocolNumber", MyDateUtils.getCurrentDateByFormat());

  • 相关阅读:
    图片的通道数和卷积核的深度
    神经网络中使用Batch Normalization 解决梯度问题
    python3没有urllib2 出现报错:语法错误
    pip安装时ReadTimeoutError解决办法
    我的学习
    动态(不定长)数组初始化
    关于c中的一些新函数
    排序算法
    vc6.0批量加注释
    endnote的安装和使用必备的几个步骤(简单有效整理版)
  • 原文地址:https://www.cnblogs.com/liudongdong666666/p/7811662.html
Copyright © 2011-2022 走看看