Simple PDF text extraction
Maintained. Last release 5 months ago. Weaker on release cadence.
pip install pdftotextpdftotext
Simple PDF text extraction
import pdftotext
# Load your PDF
with open("lorem_ipsum.pdf", "rb") as f:
pdf = pdftotext.PDF(f)
# If it's password-protected
with open("secure.pdf", "rb") as f:
pdf = pdftotext.PDF(f, "secret")
# How many pages?
print(len(pdf))
# Iterate over all the pages
for page in pdf:
print(page)
# Read some individual pages
print(pdf[0])
print(pdf[1])
# Read all the text into one string
print("\n\n".join(pdf))
Why
I needed to index a lot of PDF documents with Python. Existing solutions were slow, complicated, or both. That might not be true anymore!
Dependencies
Debian, Ubuntu, and friends
sudo apt install build-essential libpoppler-cpp-dev python3-dev
Fedora, Red Hat, and friends
sudo yum install gcc-c++ poppler-cpp-devel python3-devel
macOS
brew install poppler python
Install
pip install pdftotext