博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java将PDF的前几页拆出来组成新pdf
阅读量:7002 次
发布时间:2019-06-27

本文共 1557 字,大约阅读时间需要 5 分钟。

/**     * 截取pdfFile的第from页至第end页,组成一个新的文件名     * @param pdfFile  需要分割的PDF     * @param savepath  新PDF     * @param from  起始页     * @param end  结束页     */    public static void splitPDFFile(String respdfFile,                                    String savepath, int from, int end) throws BadPdfFormatException {        Document document = null;        PdfCopy copy = null;        try {            PdfReader reader = new PdfReader(respdfFile);            int n = reader.getNumberOfPages();            if(end==0){                end = n;            }            ArrayList
savepaths = new ArrayList
(); String staticpath = respdfFile.substring(0, respdfFile.lastIndexOf("\\")+1); //String savepath = staticpath+ newFile; savepaths.add(savepath); document = new Document(reader.getPageSize(1)); copy = new PdfCopy(document, new FileOutputStream(savepaths.get(0))); document.open(); for(int j=from; j<=end; j++) { document.newPage(); PdfImportedPage page = copy.getImportedPage(reader, j); copy.addPage(page); } document.close(); } catch (IOException e) { e.printStackTrace(); } catch(DocumentException e) { e.printStackTrace(); } }

pom.xml引入:

com.itextpdf
itextpdf
5.5.13

 

转载于:https://www.cnblogs.com/wanyong-wy/p/10276881.html

你可能感兴趣的文章
PHP一句话
查看>>
python 向上取整ceil 向下取整floor 四舍五入round
查看>>
php排序算法
查看>>
在if里赋值要注意=和==的优先级,==优先于=
查看>>
Delphi xe7 up1 调用android振动功能
查看>>
激励自己的话
查看>>
IOS 实现界面本地化(国际化)
查看>>
陶哲轩实分析命题 11.10.7
查看>>
《陶哲轩实分析》引理17.2.4证明_导数的唯一性
查看>>
站立会议5
查看>>
python中的常用模块(2)
查看>>
登陆的键盘敲击事件
查看>>
执行计划基础 统计信息
查看>>
python MD5加密方法
查看>>
mysql连接jdbc查询代码
查看>>
SpringMVC10数据验证
查看>>
处理异常Error resolving template [/login], template might not exist or might not be accessible by......
查看>>
洛谷 P1147 连续自然数和 Label:等差数列
查看>>
线程间的同步和通信机制
查看>>
Python脚本实现值更新事件赋值过程记录日志监控
查看>>