iTextPdf--the world's preferred PDF library

iText, the world's preferred PDF library

iText is a software developer toolkit that allows users to integrate PDF functionalities within their applications, processes or products. You know that PDF is one of the world's most widely used document formats, but perhaps you didn't know how it can keep being revolutionary? iText, in turn, is one of the best-documented and versatile PDF engines in the world. Don't believe us? See for yourself!


几个关键步骤:

1.快速开发:去github上搜索下载iText最新jar包,集成到项目中,你可能用到的两个链接:

https://github.com/itext/itextpdf/releases/tag/5.5.10

http://blog.csdn.net/zmx729618/article/details/52150070

2.深层定制:去github或者官网搜索下载iText源码,使用AS,SI查看并分析源码,需要用到的链接:

https://github.com/itext/itextpdf/releases/tag/5.5.10

http://itextpdf.com/


简单快速入门:

private void exportPDF() {
        String pdfile = Constants.EXPORTPATH + "xxx.pdf";
        // 1.创建一个document
        Document doc = new Document();
        //doc.setPageCount(mStrings.size());
        //有PageSize.B5,A4...
        int crWidth = Constants.CR_WIDTH;
        int ury = Constants.CR_HEIGHT - 90;
        doc.setPageSize(new Rectangle(crWidth, ury));
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(new File(pdfile));
            PdfWriter writer = PdfWriter.getInstance(doc, fos);
            doc.open();
            PdfContentByte canvas = writer.getDirectContent();

            //...署名,版权,密码保护等

            //首页
            //doc.add(new Paragraph("Welcome to Shenzhen !"));

            //内容
            for (int i = 0; i < mStrings.size(); i++) {
                if (i > 0)
                    doc.newPage();
                drawPage(canvas, i);
                fos.flush();
            }

            //尾页
            //doc.newPage();
            //doc.add(new Paragraph("Thank you ! "));

            doc.close();
            ToastUtils.showLongToast(this, "成功导出到" + pdfile);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            FileUtils.close(fos);
        }
    }




























评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值