Itext根据模板生成pdf文件并导出

/* requires itextpdf-5.1.2.jar or similar */

import java.io.*;

import com.itextpdf.text.DocumentException;

import com.itextpdf.text.pdf.*;

 

public class AddContentToPDF {

 

    public static void main(String[] args) throws IOExceptionDocumentException {

 

        /* example inspired from "iText in action" (2006), chapter 2 */

 

        PdfReader reader = new PdfReader("C:/temp/Bubi.pdf"); // input PDF

        PdfStamper stamper = new PdfStamper(reader,

          new FileOutputStream("C:/temp/Bubi_modified.pdf")); // output PDF

        BaseFont bf = BaseFont.createFont(

                BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); // set font

 

        //loop on pages (1-based)

        for (int i=1; i<=reader.getNumberOfPages(); i++){

 

            // get object for writing over the existing content;

            // you can also use getUnderContent for writing in the bottom layer

            PdfContentByte over = stamper.getOverContent(i);

 

            // write text

            over.beginText();

            over.setFontAndSize(bf, 10);    // set font and size

            over.setTextMatrix(107740);   // set x,y position (0,0 is at the bottom left)

            over.showText("I can write at page " + i);  // set text

            over.endText();

 

            // draw a red circle

            over.setRGBColorStroke(0xFF0x000x00);

            over.setLineWidth(5f);

            over.ellipse(250450350550);

            over.stroke();

        }

 

        stamper.close();

 

    }

}

 

还有另外一种使用Adobe Acrobat pro软件自行制作pdf生成表单来动态生成pdf文件的方法

博文链接:http://blog.csdn.net/top__one/article/details/65442390

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值