Remove page from PDF

前端 未结 5 635
日久生厌
日久生厌 2020-12-19 00:40

I\'m currently using iText and I\'m wondering if there is a way to delete a page from a PDF file?

I have opened it up with a reader etc., and I want to remove a page

5条回答
  •  暖寄归人
    2020-12-19 01:14

    For iText 7 I found this example:

        PdfReader pdfReader = new PdfReader(PATH + name + ".pdf");
        PdfDocument srcDoc = new PdfDocument(pdfReader);
        PdfDocument resultDoc = new PdfDocument(new PdfWriter(PATH + name + "_cut.pdf"));
        resultDoc.initializeOutlines();
    
        srcDoc.copyPagesTo(1, 2, resultDoc);
    
        resultDoc.close();
        srcDoc.close();
    

    See also here: clone-reordering-pages and here: clone-splitting-pdf-file

提交回复
热议问题