
Now let’s take a moment to learn how you can add a watermark to your PDF. When the script is finished running, you should have each page of the original PDF split into separate PDFs. Then you will write that page out to a uniquely named file.

For each page in the PDF, you will create a new PDF writer instance and add a single page to it. In this example, you once again create a PDF reader object and loop over its pages. write ( output_pdf ) if _name_ = '_main_' : path = 'Jupyter_Notebook_An_Introduction.pdf' split ( path, 'jupyter_page' ) pdf' with open ( output, 'wb' ) as output_pdf : pdf_writer. getNumPages () txt = f """ Information about. getDocumentInfo () number_of_pages = pdf. # extract_doc_info.py from PyPDF2 import PdfFileReader def extract_information ( pdf_path ): with open ( pdf_path, 'rb' ) as f : pdf = PdfFileReader ( f ) information = pdf. Feel free to swap out the imports for PyPDF2 with PyPDF4 and see how it works for you. Most of the examples in this article will work perfectly fine with PyPDF4, but there are some that cannot, which is why PyPDF4 is not featured more heavily in this article. The new PyPDF4 does not have full backwards compatibility with PyPDF2. While PyPDF2 was abandoned in 2016, it’s been revived in 2022 and is currently being actively maintained. There is a different Python 3 fork of the original pyPdf for Python 3, but that one has not been maintained for many years. All of these projects do pretty much the same thing, but the biggest difference between pyPdf and PyPDF2+ is that the latter versions added Python 3 support. There was a brief series of releases of a package called PyPDF3, and then the project was renamed to PyPDF4. The code was written to be backwards compatible with the original and worked quite well for several years, with its last release being in 2016.

After a lapse of around a year, a company called Phasit sponsored a fork of pyPdf called PyPDF2. The last official release of pyPdf was in 2010. The original pyPdf package was released way back in 2005. Free Download: Get a sample chapter from Python Tricks: The Book that shows you Python’s best practices with simple examples you can apply instantly to write more beautiful + Pythonic code.
