Registry / data / pdfminer-six

pdfminer-six

JSON →
library20260107pypypi✓ verified 49d ago

PDFMiner.six is a community-maintained fork of the original PDFMiner, a powerful Python library for parsing and analyzing PDF documents. It focuses on extracting text data, layout information, and other elements like images, and supports various PDF specifications, CJK languages, and encryption. The library is actively maintained, with frequent releases addressing bug fixes, new features, and security enhancements.

dataserialization
pip install pdfminer.six
Install & Compatibility
Where this runs
tested against v20260107 · pip install
no network on importno background threads
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.950 runs
installs and imports cleanly · install 0.0s · import 0.572s · 64.1MB
glibc
py 3.103.950 runs
installs and imports cleanly · install 3.1s · import 0.507s · 65MB
62MB installed
● package 62MB
Code
Verified usage

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

extract_text
from pdfminer.high_level import extract_text
This is the recommended high-level API for simple text extraction.
PDFParser, PDFDocument, PDFResourceManager, PDFPageInterpreter, TextConverter, LAParams
from pdfminer.pdfparser import PDFParser from pdfminer.pdfdocument import PDFDocument from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter from pdfminer.converter import TextConverter from pdfminer.layout import LAParams from pdfminer.pdfpage import PDFPage
These are components of the composable (lower-level) API for more granular control over PDF processing.

This quickstart demonstrates the simplest way to extract all text from a PDF file using the high-level `extract_text` function. The example includes creating a dummy PDF for demonstration purposes.

import io from pdfminer.high_level import extract_text # For demonstration, let's create a dummy PDF file path. # In a real scenario, this would be the path to your .pdf file. dummy_pdf_path = "example.pdf" # Create a dummy PDF file for the example to run without error # In a real application, replace this with actual PDF file handling. try: with open(dummy_pdf_path, 'wb') as f: f.write(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 41>>stream\nBT /F1 24 Tf 100 700 Td (Hello, PDFMiner.six!) Tj ET\nendstream\nxref\n0 5\n0000000000 65535 f\n0000000009 00000 n\n0000000056 00000 n\n0000000114 00000 n\n0000000213 00000 n\ntrailer<</Size 5/Root 1 0 R>>startxref\n296\n%%EOF') # Extract text from the PDF text = extract_text(dummy_pdf_path) print("Extracted Text:") print(text) except Exception as e: print(f"An error occurred: {e}") finally: # Clean up the dummy PDF file import os if os.path.exists(dummy_pdf_path): os.remove(dummy_pdf_path)
pdfminer --version
Debug
Known issues
breakingArbitrary Code Execution Vulnerabilities (CVE-2025-64512 and CVE-2025-70559) due to insecure deserialization of CMap cache files via Python's `pickle` module. This allowed attackers to execute arbitrary code by providing malicious PDF files or pickle files. [cite: 2 (release notes 20251230), 11, 12]
fix
Upgrade to version `20251230` or newer. This version replaces `pickle` with `json` for CMap storage. If you have custom `pickle` CMaps, you must convert them to JSON format using `tools/convert_cmaps_to_json.py` (included in the library). [cite: 2 (release notes 20251230), 11]
affects: <20251230
deprecatedThe third argument (generation number) to `PDFObjRef` was deprecated.
fix
Avoid using the third argument for `PDFObjRef` as it is no longer supported and can lead to `TypeError` with corrupt PDF object references.
affects: Introduced in 20250324
gotchaTextual output may contain raw character ID's (e.g., `(cid:x)` values) instead of readable characters for certain PDFs, especially those with non-standard font encodings or missing font data. This often happens when text cannot be properly converted to Unicode.
fix
Verify if text can be copy-pasted correctly from a PDF viewer; if it's gibberish there, `pdfminer.six` will also struggle. For scanned PDFs, combine `pdfminer.six` with an OCR library (e.g., `pytesseract`). Consider adjusting `LAParams` for layout analysis.
affects: All versions
gotchaProcessing very large PDF files can lead to significant memory consumption and performance issues.
fix
For large PDFs, consider extracting text page by page or in chunks using the `page_numbers` argument in functions like `extract_text` to manage memory usage more effectively.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pdfminer.high_level'
This error often occurs because the `pdfminer.six` library, which contains the `high_level` module, is either not installed, or there's a conflict with the older, unmaintained `pdfminer` package.
fix
Ensure you have `pdfminer.six` installed correctly and not the old `pdfminer`. If you have both, uninstall the old one. Use `pip install pdfminer.six` or `pip install --upgrade pdfminer.six`. If using a virtual environment, activate it first.
pdfminer.pdfdocument.PDFTextExtractionNotAllowed: Text extraction is not allowed
This error indicates that the PDF document is encrypted or has usage restrictions that prevent text extraction.
fix
You can attempt to extract text by providing the correct password using the `password` argument in functions like `extract_text`. If there's no password, you might be able to bypass the check by setting `check_extractable=False` in some lower-level functions, though this is not always recommended for security-restricted documents.
AttributeError: module 'pdfminer' has no attribute 'high_level'
This typically arises when code written for `pdfminer.six` attempts to use the `high_level` module, but an older `pdfminer` library (which does not have this module) is being imported or is shadowing the `pdfminer.six` installation.
fix
Verify that `pdfminer.six` is the only PDFMiner-related package installed and is accessible in your Python environment. Uninstall any older `pdfminer` installations (e.g., `pip uninstall pdfminer`) and ensure `pdfminer.six` is properly installed (`pip install pdfminer.six`). Also, ensure you are importing `from pdfminer.high_level import extract_text` or similar.
(cid:x) values in textual output
This is a common issue where `pdfminer.six` cannot map a character ID (CID) to a Unicode character, often due to custom fonts, non-standard PDF encoding, or embedded fonts not providing sufficient information for proper decoding.
fix
This is often a limitation of the PDF itself. A quick check is to copy-paste the text from a PDF viewer; if it's gibberish, `pdfminer.six` likely won't do better. For programmatic solutions, one might need to apply custom character mapping or use OCR for such PDFs.
KeyError: 'N'
This `KeyError` (or similar for keys like 'Type', 'Resources', 'MediaBox') often indicates that the PDF document is malformed or does not strictly adhere to the PDF specification, missing expected dictionary keys that `pdfminer.six` anticipates.
fix
This typically points to an issue with a specific, non-standard PDF file. There isn't a universal code fix, but sometimes updating `pdfminer.six` to the latest version can resolve issues with certain malformed PDFs, as the library often adds robustness for such cases.
Upgrade
Version history
20260107latest on PyPI
Audit
Dependencies
charset-normalizerrequiredRequired for character set detection.
cryptographyrequiredRequired for handling encrypted PDFs.
PillowoptionalOptional, required for image extraction functionality when installing with the `[image]` extra.
Agent activity
12 hits · last 30 days
seranking-bot
4
node
2
ahrefsbot
2
googlebot
2
Amazon
1
Resources