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为需要截取的末页。
Tale、车车