PyPDF2 | A utility to read and write PDFs with Python | Document Editor library

 by   mstamy2 Python Version: 1.27.0 License: Non-SPDX

kandi X-RAY | PyPDF2 Summary

kandi X-RAY | PyPDF2 Summary

PyPDF2 is a Python library typically used in Editor, Document Editor applications. PyPDF2 has no bugs, it has no vulnerabilities, it has build file available and it has medium support. However PyPDF2 has a Non-SPDX License. You can download it from GitHub.

PyPDF2 is a pure-python PDF library capable of splitting, merging together, cropping, and transforming the pages of PDF files. It can also add custom data, viewing options, and passwords to PDF files. It can retrieve text and metadata from PDFs as well as merge entire files together.

            kandi-support Support

              PyPDF2 has a medium active ecosystem.
              It has 4088 star(s) with 1044 fork(s). There are 150 watchers for this library.
              It had no major release in the last 12 months.
              There are 293 open issues and 137 have been closed. On average issues are closed in 1336 days. There are 81 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of PyPDF2 is 1.27.0

            kandi-Quality Quality

              PyPDF2 has 0 bugs and 0 code smells.

            kandi-Security Security

              PyPDF2 has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              PyPDF2 code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              PyPDF2 has a Non-SPDX License.
              Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.

            kandi-Reuse Reuse

              PyPDF2 releases are available to install and integrate.
              Build file is available. You can build the component from source.
              Installation instructions are not available. Examples and code snippets are available.
              PyPDF2 saves you 1859 person hours of effort in developing the same functionality from scratch.
              It has 4103 lines of code, 293 functions and 16 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed PyPDF2 and discovered the below as its top functions. This is intended to give you an instant insight into PyPDF2 implemented functionality, and help decide if they suit your requirements.
            • Reads a Pdf file .
            • Merge the file object into a PdfFile .
            • Writes to the specified stream .
            • Merge the content of a page to a resource .
            • Reads a string from a stream .
            • Remove a child of this node .
            • Decode data .
            • Reads the inline image .
            • Reads an object from a stream .
            • Algorithm based on a password .
            Get all kandi verified functions for this library.

            PyPDF2 Key Features

            No Key Features are available at this moment for PyPDF2.

            PyPDF2 Examples and Code Snippets

            No Code Snippets are available at this moment for PyPDF2.

            Community Discussions


            Is there any difference between using a decorator and applying the function directly?
            Asked 2022-Apr-17 at 22:00

            I recently became the maintainter of PyPDF2 - a library which is pretty old and still has some code that deals with Python versions before 2.4. While I want to drop support for 3.5 and older soon, I see some parts where I'm uncertain why they were written as they are.

            One example is this:

            What is in the code:



            Answered 2022-Apr-17 at 22:00

            The first version is just the pre-2.4 way to use staticmethod. The two versions aren't quite equivalent, but the difference is so tiny it almost never matters.

            Specifically, on Python versions that support decorator syntax, the one difference is that the second version passes the original function directly to staticmethod, while the first version stores the original function to a and then looks up the a variable to find the argument to pass to staticmethod. This can technically matter in very weird use cases, particularly with metaclasses, but it'd be highly unlikely. Python 2 doesn't even support the relevant metaclass feature (__prepare__).



            Extracting information from multiple resumes all in PDF format
            Asked 2022-Feb-28 at 17:07

            I have a data set with a column which has google drive link for resumes, I have 5000 rows so there are 5000 links , I am trying to extract information like years of experience and salary from these resumes in 2 separate columns. so far I've seen so many examples mentioned here on SO.

            For example: the code mentioned below can only read the data from one file , how do I replicate this to multiple rows ?

            Please help me with this , else I will have to manually go through 500 resumes and fill in the data

            Hoping that I'll get a solution for this painful problem that I have.



            Answered 2022-Feb-28 at 17:07

            Use a loop. Basically you put your main code into a function (easier to read) and create a list of filenames. Then you iterate over this list, using the values from the list as argument for your function:

            Note: I didn't check your scraping code, just showing how to loop. There are also way more efficient ways to do this, but I'm assuming you're somewhat of a Python beginner so lets keep it simple to start with.



            Text rotated when merging pdf pages using Pypdf2 and Reportlab
            Asked 2022-Feb-27 at 07:24

            I'm trying to merge two pages one from reportlab that has the text I wish and another one is my source pdf

            But when I merge those two pages, my text is rotated 90 degree

            Pdf created using Report lab -> Overlay Created using Reportlab

            when Merged with Source pdf -> Source Pdf

            Code that I have Used :



            Answered 2022-Feb-27 at 07:24

            Refered to this and created an own solution -> Python PyPDF2 merge rotated pages



            Why isn't autocompleteworking in vscode for python external packages?
            Asked 2022-Feb-19 at 19:30

            I am new to python and I guess pyCharm is the most preferred IDE for python but I want to stick to vscode if possible. I have the python extension installed in vscode and autocomplete works fine for default python packages but for external packages like pillow or PyPDF2, its not working. I created a virtual environment where I installed the above 2 packages using pip and even checked if the packages are installed using pip freeze. Pip freeze is showing:



            Below is my project structure. I need to import PyPDF2 module from Also, if it helps, I am using python 3.9.6. Any help or suggestions are greatly appreciated.



            Answered 2022-Feb-19 at 19:29

            Did you select the interpreter inside the vscode?
            Enter vscode and type



            Merge PDF pages to 1 file without generating single page files
            Asked 2022-Feb-14 at 15:39

            The goal is to take a set of jpg/tif images and convert them into 1 text-searchable PDF. I am using Python's PyPDF2 and pytesseract to accomplish this; however, I am unable to find a method of combining these pages without saving each page as its own PDF. Turns out some of these sets could be 1k-10k pages so saving each page individually is unfortunately no longer feasible ... here's what I've got so far:



            Answered 2022-Feb-14 at 15:37


            Parse PDF shape data in python
            Asked 2022-Feb-03 at 07:44

            I am trying to put together a script to fix PDFs a large number of PDFs that have been exported from Autocad via their DWG2PDF print driver.

            When using this driver all SHX fonts are rendered as shape data instead of text data, they do however have a comment inserted into the PDF at the expected location with the expected text.

            So far in my script I have got it to run through the PDF and insert hidden text on top of each section, with the text squashed to the size of the comment, this gets me 90% of the way and gives me a document that is searchable.

            Unfortunately the sizing of the comment regions is relatively course (integer based) which makes it difficult to accurately determine the orientation of short text, and results in uneven sized boxes around text.

            What I would like to be able to do is parse through the shape data in the PDF, collect anything within the bounds of the comment, and then determine a smaller and more accurate bounding box. However all the information I can find is by people trying to parse through text data, and I haven't been able to find anything at all in terms of shape data.

            The below image is an example of the raw text in the PDF, the second image shows the comment bounding box in blue, with the red text being what I am setting to hidden to make the document searchable, and copy/paste able. I can get things a little better by shrinking the box by a fixed margin, but with small text items the low resolution of the comment box coordinate data messes things up.

            To get this far I am using a combination of PyPDF2 and reportlab, but am open to moving to different libraries.



            Answered 2022-Feb-03 at 07:44

            I didn't end up finding a solution with PyPDF2, I was able to find an easy way to iterate over shape data in pdfminer.six, but then couldn't find a nice way in pdfminer to extract annotation data.

            As such I am using one library to get the annotations, one to look at the shape data, and last of all a third library to add the hidden text on the new pdf. It runs pretty slowly as sheet complexity increases but is giving me good enough results, see image below where the rough green borders as found in the annotations are shrunk to the blue borders surrounding the text. Of course I don't draw the boundaries, and use invisible text for the actual program output, giving pretty good selectable/searchable text.

            If anyone is interested in looping over the shape data in PDFs the below snippet should get you started.



            Merging cells, in the same column, in the same df- Python
            Asked 2022-Jan-26 at 15:29

            I am attempting to merge two cells together. The reason for this is due to the fact that every unit under 'Chassis' should be an alphanumeric (ABCD123456) however the PO provided occasionally shifts the last number to the next row (no other data on said row) making the data look like this Example I initially tried to create a statement that looked at the cell, confirmed it was less one number, then would look at the next cell, and merge the two. Never got that to even come close to manifesting any results. I then decided to replicate the data frame, shift the second data frame(so the missing number is on the same row), and merge them together. This is where I am now. Error Msg This is my first real bit of code in Python so I am fairly certain I am doing inefficient things so by all means let me know where I can improve.

            Currently I have this...

            Col1 Chassis Other Columns... Other Columns 2... Nan ABCD12345 ABC 123 Nan 6 Nan Nan Nan WXYZ987654 GHI 456 Nan QRSTU654987 Nan 789 Nan MNOP999999 XYZ Nan

            End Goal is this...

            Col1 Chassis Other Columns... Other Columns 2... Nan ABCD123456 ABC 123 Nan WXYZ987654 GHI 456 Nan QRSTU654987 Nan 789 Nan MNOP999999 XYZ Nan ...


            Answered 2022-Jan-26 at 15:29

            Create a virtual group and merge rows of this group for Chassis column:



            PyPDF2.PdfFileMerger only writes first pdf
            Asked 2022-Jan-26 at 09:54

            I have several Pdfs that I want to merge together. To do this I referenced this Documentation as well as this Merge PDF files post as reference. My code reads from the the directory where my pdfs lie and tries to write the new pdf into another directory



            Answered 2022-Jan-26 at 09:54

            For posterity:

            Add files to the merger with merger.append(open(filepath, 'rb')) because PyPDF has some odd internal issues with file reader/writers.



            Iterate Over Dictionary to Combine PDFs, Rename
            Asked 2022-Jan-16 at 19:03

            I am attempting to create a function that combines pdf files into a single file. I am attempting to take a dictionary that is constructed as follows:



            Answered 2022-Jan-16 at 19:03

            The problem is not with the algorithm.

            I don't use this package myself, but what I noticed is that you don't use the



            Python code to extract txt from PDF document
            Asked 2022-Jan-14 at 22:44

            I have been trying to convert some PDFs into .txt, but most sample codes I found online have the same issue: They only convert one page at a time. I am kinda new to python, and I am not finding how to write a substitute for the .GetPage() method to convert the entire document at once. All help is welcomed.



            Answered 2022-Jan-14 at 22:44

            You could do this with a for loop. Extract the text from the pages in the loop and append them to a list.


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install PyPDF2

            You can download it from GitHub.
            You can use PyPDF2 like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.


            Documentation is available at
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • HTTPS


          • CLI

            gh repo clone mstamy2/PyPDF2

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link