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());

  • 相关阅读:
    python学习日记(OOP访问限制)
    python学习日记(OOP——@property)
    python学习日记(OOP——静态方法和类方法)
    python学习日记(isinstance和issubclass)
    python学习日记(OOP——反射)
    python学习日记(初识面向对象)
    python学习日记(内置、匿名函数练习题)
    python学习日记(内置函数)
    python学习日记(内置函数补充)
    Raft一致性协议
  • 原文地址:https://www.cnblogs.com/liudongdong666666/p/7811662.html
Copyright © 2011-2022 走看看