From ca929f1dfd13e193eefb6898e8ab1b8fd6d22982 Mon Sep 17 00:00:00 2001 From: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> Date: Thu, 1 Apr 2021 15:27:37 +0200 Subject: [PATCH] Adding PdfReader.remove_page --- pdfrw/pdfreader.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pdfrw/pdfreader.py b/pdfrw/pdfreader.py index c2ae030..af99ace 100644 --- a/pdfrw/pdfreader.py +++ b/pdfrw/pdfreader.py @@ -689,3 +689,15 @@ def __init__(self, fname=None, fdata=None, decompress=False, # For compatibility with pyPdf def getPage(self, pagenum): return self.pages[pagenum] + + def remove_page(self, index): + ''' + Usage example: + + PdfWriter(trailer=PdfReader('src.pdf').remove_page(1)).write('out.pdf') + ''' + del self.pages[index] + self.private.numPages = self.numPages - 1 + del self.Root.Pages.Kids[index] + self.Root.Pages.Count = PdfObject(len(self.Root.Pages.Kids)) + return self