Springboot + PDFbox 读取pdf文件每页前面插入

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

采用自助打印一体机,时时加盖鲜章,盖鲜章是垂直加盖,内容打印是在反面,需要在pdf 文件的每页前面添加空白页。

一、pdfbox文档

pdfbox 文档https://iowiki.com/pdfbox/pdfbox_index.html

二、具体实现

1.引入pdfbox 

<dependency> 
         <groupId>org.apache.pdfbox</groupId> 
         <artifactId>pdfbox</artifactId> 
         <version>2.0.1</version> 
      </dependency>   

2.插入空白页

 public static boolean addBlankPage(String srcPdf,String targetPdf){
        try {
            File file = new File(srcPdf);
            PDDocument pdDocument = PDDocument.load(file);
            PDDocument document = new PDDocument();
            for (int i=0;i<pdDocument.getNumberOfPages();i++) {
                PDPage page = pdDocument.getPage(i);
                document.addPage(new PDPage());
                document.addPage(page);
            }
            document.save(targetPdf);
            document.close();
            pdDocument.close();
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

总结

先读取到原始pdf文件的总页数,在将每页拆分成单页添加到新的文档

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值