Read the contents of documents in various formats and directly output text for AI analysis. Supports direct reading of documents inside archives without manual extraction.
📦 Supported Formats
Documents
| Format | Extension | Description |
|---|---|---|
.pdf |
Supports text extraction, depends on poppler-utils | |
| Microsoft Word | .docx |
Fully extracts all paragraph text |
| Microsoft Excel | .xlsx |
Output by Sheet, with each Sheet output as table text |
| Microsoft PowerPoint | .pptx |
Output in blocks by Slide |
| Rich Text Format | .rtf |
|
| OpenDocument Text | .odt |
|
| HTML | .html/.htm |
Extract body text |
| Plain text | .txt/.md/.json/.xml/.py/.js etc. |
Read directly |
Archives
| Format | Extension | Function |
|---|---|---|
| ZIP | .zip |
List files ➜ Read specified document |
| TAR | .tar/.tar.gz/.tgz/.tar.bz2 |
List files ➜ Read specified document |
| RAR | .rar |
List files ➜ Read specified document |
| 7-Zip | .7z |
List files ➜ Read specified document |
🚀 Quick Start
Dependency Installation
Python packages:
pip install textract python-docx openpyxl python-pptx rarfile py7zr --break-system-packages
System dependencies (Ubuntu/Debian):
apt-get install -y poppler-utils antiword unrtf tidy libxml2-dev libxslt1-dev
💡 Usage Examples
1. Read a local document directly
# 读取 PDF 文件
python {baseDir}/scripts/document_reader.py --file /path/to/document.pdf
# 读取 Word 文档
python {baseDir}/scripts/document_reader.py --file /path/to/report.docx
# 读取 Excel 文件(输出带 Sheet 分隔的表格文本)
python {baseDir}/scripts/document_reader.py --file /path/to/data.xlsx
# JSON 格式输出(方便程序处理)
python {baseDir}/scripts/document_reader.py --file /path/to/data.xlsx --format json
2. Process archives
First list which files are in the archive:
# 列出 ZIP 包内容
python {baseDir}/scripts/document_reader.py --list /path/to/archive.zip
# 列出 RAR 包内容
python {baseDir}/scripts/document_reader.py --list /path/to/archive.rar
# 列出 7z 包内容
python {baseDir}/scripts/document_reader.py --list /path/to/archive.7z
Read a specified document in the archive:
# 读取 ZIP 包内的 Word 文档
python {baseDir}/scripts/document_reader.py --file /path/to/archive.zip --inner-path document.docx
# 读取 7z 包内的 PDF
python {baseDir}/scripts/document_reader.py --file /path/to/archive.7z --inner-path report.pdf
Output Examples
Read document:
=== report.pdf ===
# 项目进度报告
## 本周完成
1. 完成了前端界面开发
2. 修复了三个 Bug
3. 编写了接口文档
...
List archive:
Archive: data.zip
Found 3 file(s):
readme.txt
docs/report.pdf
data/sheet.xlsx
✨ Features
- 🎯 Ready to use out of the box — Use it directly after installing dependencies, no complex configuration required
- 📦 Supports archives — No manual extraction needed, directly list and read internal files
- 🔍 Fuzzy matching — Case-insensitive filename matching, automatically tries when no exact match is found
- 🎨 Multiple output formats — Both human-readable text and JSON programmatic interfaces are supported
- 🧩 Full support for all commonly used formats — Full coverage of office documents + archives
📝 Use Cases
- AI analysis of various office documents
- Batch reading of document contents inside archives
- Quickly view attachment contents
- Data extraction and preprocessing
Author
Created by xiaoya Liu with OpenClaw