Registry / data / pdfminer

pdfminer

JSON →
library20191125pypiunverified

PDFMiner is a Python library for extracting and analyzing text data from PDF documents, focusing on precise text location and layout information. The version `20191125` is the last release of the original `euske/pdfminer` project. It supports Python 3.6 and above, but has not been actively maintained since 2020. For ongoing development and community support, the `pdfminer.six` fork is recommended.

pip install pdfminer
INSTALL
IMPORT
SIG · PDFMINER
P
pdfminer
dataenv20191125
Install
18.9s avg
Import
143ms
Disk
34MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v20191125 · 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.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.144s · 36MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 18.9s · import 0.141s · 37MB
34MB installed
● package 34MB
Code
Verified usage

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

PDFResourceManager
✓ from pdfminer.pdfinterp import PDFResourceManager
PDFPageInterpreter
✓ from pdfminer.pdfinterp import PDFPageInterpreter
PDFPage
✓ from pdfminer.pdfpage import PDFPage
PDFParser
✓ from pdfminer.pdfparser import PDFParser
PDFDocument
✓ from pdfminer.pdfdocument import PDFDocument
TextConverter
✓ from pdfminer.converter import TextConverter
LAParams
✓ from pdfminer.layout import LAParams

This quickstart demonstrates how to extract text from a PDF file using PDFMiner's core components. It initializes a resource manager, a text converter, and a page interpreter to process the PDF document page by page. A dummy `dummy.pdf` file is created if not found, allowing the code to be runnable for demonstration purposes. This reflects the more verbose API usage typical of the original PDFMiner, as opposed to the simplified `high_level` API found in `pdfminer.six`.

import os from io import StringIO from pdfminer.converter import TextConverter from pdfminer.layout import LAParams from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter from pdfminer.pdfpage import PDFPage from pdfminer.pdfparser import PDFParser def extract_text_from_pdf(pdf_path): # Ensure a dummy PDF exists for demonstration, or replace with a real path if not os.path.exists(pdf_path): print(f"Error: PDF file not found at {pdf_path}. Creating a dummy PDF for demonstration.") # In a real scenario, you'd handle the missing file appropriately. # For a runnable example, we'll create a simple dummy file. try: from reportlab.pdfgen import canvas c = canvas.Canvas(pdf_path) c.drawString(100, 750, "Hello, PDFMiner!") c.drawString(100, 730, "This is a dummy PDF for testing.") c.save() print(f"Dummy PDF created at {pdf_path}") except ImportError: print("Please install reportlab (`pip install reportlab`) to create dummy PDF, or provide a real PDF.") return "" rsrcmgr = PDFResourceManager() retstr = StringIO() laparams = LAParams() device = TextConverter(rsrcmgr, retstr, laparams=laparams) with open(pdf_path, 'rb') as fp: parser = PDFParser(fp) document = PDFDocument(parser) interpreter = PDFPageInterpreter(rsrcmgr, device) for page in PDFPage.create_pages(document): interpreter.process_page(page) text = retstr.getvalue() device.close() retstr.close() return text if __name__ == '__main__': pdf_file = 'dummy.pdf' extracted_content = extract_text_from_pdf(pdf_file) print("\n--- Extracted Text ---") print(extracted_content)
pdf2txt.py --version
Debug
Known issues
breakingThe original `pdfminer` project (euske/pdfminer) is no longer actively maintained since 2020. While the latest version `20191125` supports Python 3, new features, bug fixes, and community support are primarily found in its actively maintained fork, `pdfminer.six`.
fix
Consider migrating to `pdfminer.six` for an actively developed and supported version (`pip install pdfminer.six`).
affects: <=20191125
gotchaPDFMiner struggles with text extraction from PDFs with complex layouts (e.g., multi-column, nested tables) and cannot extract text from scanned PDFs (images) without external Optical Character Recognition (OCR) tools.
fix
For complex layouts, extensive customization of `LAParams` or post-processing may be required. For scanned PDFs, integrate with OCR libraries like Tesseract or pre-process with tools that extract images for OCR.
affects: All versions
gotchaOutput may contain raw character IDs like `(cid:x)` instead of readable text, especially for non-standard fonts or encoding issues. This happens when the font is not properly mapped to Unicode.
fix
Verify if text can be copy-pasted correctly from a PDF viewer. If it can, try adjusting `LAParams` or exploring `pdfminer.six` which might have better font/encoding handling. Otherwise, it might be an inherent limitation of the PDF itself.
affects: All versions
Errors
Common errors & fixes
AttributeError: '_io.BytesIO' object has no attribute 'catalog'
This error typically occurs when a file-like object (like `io.BytesIO`) is passed directly to `PDFPage.create_pages()` or similar functions, but the API expects a `PDFDocument` object that has already been parsed by a `PDFParser`. This indicates incorrect API usage.
fix
Ensure you correctly parse the file first using `PDFParser` to create a `PDFDocument` instance, and then pass the `PDFDocument` object to `PDFPage.create_pages()`. Refer to the quickstart example for correct API flow.
ModuleNotFoundError: No module named 'pdfminer.six'
This usually means you have installed the original `pdfminer` package but are attempting to import modules or use `high_level` functions specific to the `pdfminer.six` fork. Or, `pdfminer.six` was not installed at all.
fix
If you intend to use `pdfminer.six` (recommended), ensure you install it with `pip install pdfminer.six`. If you're sticking to the original `pdfminer`, use its specific import paths and API patterns. The original `pdfminer` does not expose a `pdfminer.high_level` module.
UnicodeEncodeError: 'charmap' codec can't encode character...
Encoding issues are common when handling diverse text content in PDFs, especially across different operating systems or locales, or when writing to files without specifying the correct encoding.
fix
Always specify `encoding='utf-8'` when creating output files or `StringIO` objects if you expect Unicode characters. For `TextConverter`, ensure the `outfp` (output file pointer) is opened with `encoding='utf-8'` or handle character sets explicitly.
Upgrade
Version history
20191125latest on PyPI · released Nov 25, 2019
Audit
Dependencies
pycryptodomerequiredRequired for handling encrypted PDF documents.
Agent activity
8 hits · last 30 days
node
8
Resources

No resource links recorded.

pdfminer — pip install pdfminer · libregistry