Registry / data / pdftotext

pdftotext

JSON →
library3.0.0pypypiunverified

pdftotext is a Python wrapper for the `pdftotext` command-line utility (part of the Poppler PDF rendering library). It provides a simple, efficient way to extract text from PDF documents. The current version is 3.0.0, and it has a moderate release cadence, with major updates happening less frequently than minor bug fixes.

pip install pdftotext
INSTALL
IMPORT
SIG · PDFTOTEXT
P
pdftotext
datapythonv3.0.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pdftotext
import pdftotext

This quickstart demonstrates how to load a PDF, extract all text by joining its pages, and access text from individual pages using list-like indexing. It also includes error handling for the common case where the underlying poppler-utils `pdftotext` command is not found.

import pdftotext import os # Create a dummy PDF file for demonstration dummy_pdf_content = b"%PDF-1.4\n1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Count 1/Kids[3 0 R]>>endobj 3 0 obj<</Type/Page/Parent 2 0 R/MediaBox[0 0 612 792]/Contents 4 0 R>>endobj 4 0 obj<</Length 44>>stream\nBT /F1 24 Tf 100 700 Td (Hello, pdftotext!) Tj ET\nendstream\nendobj\nxref\n0 5\n0000000000 65535 f\n0000000009 00000 n\n0000000055 00000 n\n0000000109 00000 n\n0000000216 00000 n\ntrailer<</Size 5/Root 1 0 R>>startxref 303\n%%EOF" with open("dummy.pdf", "wb") as f: f.write(dummy_pdf_content) # Load your PDF file try: with open("dummy.pdf", "rb") as f: pdf = pdftotext.PDF(f) # Get all text from the document (each element is a page) full_text = "\n\n".join(pdf) print("--- Full PDF Text ---") print(full_text) # Get text from a specific page (e.g., the first page) if len(pdf) > 0: first_page_text = pdf[0] print("\n--- First Page Text ---") print(first_page_text) else: print("\nNo pages found in PDF.") except pdftotext.Error as e: print(f"Error processing PDF: {e}. Make sure poppler-utils is installed.") finally: # Clean up the dummy file if os.path.exists("dummy.pdf"): os.remove("dummy.pdf")
pdftotext --version
Debug
Known issues
breakingThe `pdf.pages` attribute was removed in version 3.0.0. The `pdftotext.PDF` object now behaves like a list of strings, where each string is the text of a page. Old code referencing `pdf.pages` will break.
fix
Replace `for page in pdf.pages:` with `for page in pdf:` and `pdf.pages[0]` with `pdf[0]`.
affects: >=3.0.0
gotchaThis library is a wrapper for the `pdftotext` command-line utility, which is part of the Poppler PDF rendering library. You must install Poppler (e.g., `poppler-utils` on Linux, `poppler` on macOS) on your system for `pdftotext` to function.
fix
Install `poppler-utils` (Debian/Ubuntu), `poppler` (macOS via Homebrew), or the equivalent package for your operating system. Ensure the `pdftotext` executable is in your system's PATH.
affects: All versions
gotchaProcessing very large or complex PDF documents can be memory-intensive, as the library often loads the entire document into memory before extraction. This can lead to `MemoryError` or slow performance.
fix
For extremely large PDFs, consider processing them in chunks if possible (though `pdftotext` isn't designed for this granular control) or explore alternative libraries better suited for streaming or lower memory footprint operations.
affects: All versions
Upgrade
Version history
3.0.0latest on PyPI · released Dec 6, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
pdftotext — pip install pdftotext · libregistry