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.
pip install pdfminer.sixVerified import paths — ran on the pinned version, not inferred.
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.
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]
Avoid using the third argument for `PDFObjRef` as it is no longer supported and can lead to `TypeError` with corrupt PDF object references.
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.
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.
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.
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.
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.
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.
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.