Java使用itext生成PDF 然后将多个PDF打包zip下载

先上pom依赖 用于生成pdf文件

        <!--pdf start-->
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>kernel</artifactId>
            <version>7.0.3</version>
        </dependency>
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>io</artifactId>
            <version>7.0.3</version>
        </dependency>
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>layout</artifactId>
            <version>7.0.3</version>
        </dependency>
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>font-asian</artifactId>
            <version>7.0.3</version>
        </dependency>
        <!--pdf end-->

首先构建 Document对象

//字节输出流(包直接是java.io)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = new PdfWriter(baos);
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);

然后构建pdf内容

        //添加标题
        Paragraph title = new Paragraph("" + "测试名称").setFont(watermark)
                .setFontSize(22)//设置字体大小
                .setBold()//设置文字为粗体
                .setFontColor(new DeviceRgb(0, 0, 0))//设置字体颜色
                .setTextAlignment(TextAlignment.CENTER)//文字水平居中
                .setFixedLeading(22)//类似于css中的行高
                ;
        //将内容添加到PDF页面上
        document.add(ti
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值