A small, dependency-free Python library for extracting text from PDF files.
justpdf is a regex-based parser, not a full implementation of the PDF
specification. It handles the common case — a PDF with plain indirect
objects and FlateDecode-compressed content streams — well. It does not
handle encrypted PDFs, PDFs built from cross-reference streams / object
streams, or pages with more than one content stream.
pip install justpdfimport justpdf
text = justpdf.read_pdf("document.pdf")from justpdf import PdfReader
reader = PdfReader("document.pdf")
print(reader.page_count)
print(reader.pages[0].text)
print(reader.extract_text())
print(reader.metadata)
print(reader.search("keyword"))Reads a PDF and returns all of its text, pages joined by a blank line.
reader.pages— list ofPageobjects, in file orderreader.page_count— number of pagesreader.metadata— dict of simple/Infofields (e.g.Title,Author)reader.extract_text()— all pages' text, joined by a blank linereader.search(query, case_sensitive=False)— list of{"page": int, "line": int, "text": str}matches, one per matching line
page.number— 1-based page numberpage.text— the page's extracted text (computed on first access)
justpdf.PdfError— base class for library errorsjustpdf.UnsupportedPdfError— raised when the file isn't a PDF, or its structure isn't onejustpdfunderstands (e.g. no pages found)
Reading a missing file raises the standard FileNotFoundError.
- Text-showing operators:
Tj,TJ,'," - Literal strings (
(...)) with basic escape sequences - Hex strings (
<...>), including UTF-16BE andToUnicodeCMap lookups - FlateDecode-compressed content streams
- Basic
/Infometadata (Title, Author, etc.) - Line-based text search across pages
- No support for encrypted PDFs.
- No support for cross-reference streams or object streams (i.e. PDFs written to the newer, more compact xref format used by some tools).
- A page's
/Contentsmust be a single stream, not an array of streams. - Only the first
/ToUnicodeCMap found in the file is used, so PDFs that embed multiple differently-encoded fonts may decode incorrectly for all but one of them. - Page order follows the order objects appear in the file, which is usually — but not guaranteed to be — reading order.
- No image extraction, no PDF writing/modification.
If you hit one of these limits, the library raises UnsupportedPdfError
or (for the CMap/ordering caveats) may just produce imperfect text rather
than an error.
git clone https://github.com/Pujan-Dev/justpdf.git
cd justpdf
pip install -e ".[dev]"
pytestApache License 2.0. See LICENSE.