zoukankan      html  css  js  c++  java
  • java从一个pdf中取出指定页生成一个新的pdf

    public static void partitionPdfFile(String pdfFile,
                                            String newFile, int from, int end) {
            Document document = null;
            PdfCopy copy = null;
            try {
                PdfReader reader = new PdfReader(pdfFile);
                int n = reader.getNumberOfPages();
                if (end == 0) {
                    end = n;
                }
                
                document = new Document(reader.getPageSize(1));
                copy = new PdfCopy(document, new FileOutputStream(newFile));
                document.open();
                for (int j = from; j <= end; j++) {
                    document.newPage();
                    PdfImportedPage page = copy.getImportedPage(reader, j);
                    copy.addPage(page);
                }
                document.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    

      取出指定页的pdf生成新的pdf,参数说明:

    pdfFile为源pdf,
    newFile为需要新生成的pdf,
    from为需要截取的起始页,

    end为需要截取的末页。
  • 相关阅读:
    git命令
    svg学习系列02-简单的svg图形和线条
    svg学习系列01-svg简介
    jQuery分页插件
    svg简介
    css3选择器
    sublime使用
    HTML5新特性
    html新的语义化标签和表单控件
    DOM详解
  • 原文地址:https://www.cnblogs.com/taleche/p/13183521.html
Copyright © 2011-2022 走看看