4

I'm looking for well-maintained and well-documented powerful PDF parsing libraries for Python (mainly to extract and parse data from various types of PDFs with different/unpredictable structures, including with the help of reliable and powerful OCR).

Currently I'm aware of the following main projects:


PDFMiner: https://github.com/euske/pdfminer (last commit 11 days ago)

PDFMiner.six: https://github.com/pdfminer/pdfminer.six (last commit 3 days ago - seems to be the most actively maintained project)

^-- not sure to have understood exactly the difference between the two.

The PDFMiner API appears to me a bit overly-complicated to use - see a good example here.


PyPDF2: https://github.com/mstamy2/PyPDF2 (last commit in June 2018)

PyPDF4: https://github.com/claird/PyPDF4 (last commit in May 2019)

Short version: PyPDF4 is a clean break designed to do what PyPDF2 did, but on a more sustainable, business-worthy basis. Yes, in principle we could have just reconfigured PyPDF2 (or PyPDF3, for that matter) until it arrived where we want PyPDF4 to be. Our judgment was that the cost of leaving PyPDF2's assets and liabilities behind was less than the gain from a fresh organizational start.


Modern table parser for PDF with Camelot-py (https://github.com/camelot-dev/camelot) -> this is a great project, but currently only covers parsing of tables in PDFs. Plus it appears to rely on PyPDF2 & PDFMiner.six for actually reading the PDF.


So what other general-purpose powerful, reliable (=accurate and robust) and modern (=with great API) open-source PDF parsing library that is well maintained exists for Python?

2 Answers 2

4

Finally I went for OCRmyPDF (https://github.com/jbarlow83/OCRmyPDF), which uses tesseract for the actual OCR part (https://github.com/tesseract-ocr/tesseract) - as I understand tesseract is a OCR tool that has been open-sourced by Google.

OCRmyPDF has great documentation, also works from the command line and has many language packs:

ocrmypdf -l eng pdf_to_ocr.pdf new_pdf_with_ocr.pdf


In order to extract text from the PDF, the best tool I found is pdftotext (https://github.com/jalan/pdftotext), which is a Python wrapper for Poppler (https://poppler.freedesktop.org/). I am getting very satisfying results with this tool, far better than PyPDF2.


Update: Here are some top-of-the-line PDF readers & writers for Python:

Be sure to check these out. Although for text extraction, I must say I still prefer pdftotext for basic usage as it nicely preserves layout order using spaces.

3
  • Good question & good answer. Please click the tick to accept your own answer. Doing so will help others who read this question in future. Thanks for that recommendation :-)
    – Mawg
    Commented Nov 19, 2019 at 13:20
  • 1
    Thanks for the tip, I missed that last step in accepting the answer :) indeed hope this info can save others some time.
    – Jean Monet
    Commented Nov 19, 2019 at 15:45
  • Welcome aboard. Hope you'll be active :-)
    – Mawg
    Commented Nov 19, 2019 at 18:14
1

I'm now the maintainer of pypdf and PyPDF2. I merged everything back into pypdf. pypdf is the way to go. PyPDF2 will be deprecated.


Original answer:

PyPDF2 is mainained again since April 2022. We made massive improvements in text extraction and added type annotations. The docs were improved, the interface is now more pythonic.

Internally, we deprecated Python 3.5 and lower + added a lot of unit tests. This simplifies the development / maintenance.

PyPDF2 is free and open source.

PyPDF2 is a pure-python library without any dependencies.

1
  • Great news, cheers for that!
    – Jean Monet
    Commented Jun 10, 2022 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.