Document Handler
Extract text, metadata, and content from any document format.
Supported Formats
| Format | Extensions | Text Extract | Metadata | Convert |
|---|
| PDF | .pdf | ✅ pdftotext | ✅ pdfinfo | ✅ pdftoppm |
| Word |
.docx | ✅ unzip + xml | ✅ | ✅ |
| Excel | .xlsx | ✅ unzip + xml | ✅ | ✅ |
| PowerPoint | .pptx | ✅ unzip + xml | ✅ | ✅ |
| EPUB | .epub | ✅ unzip + html | ✅ | ✅ |
| RTF | .rtf | ✅ textutil | ✅ | ✅ |
| OpenDocument | .odt, .ods, .odp | ✅ unzip + xml | ✅ | ✅ |
Quick Commands
PDF
CODEBLOCK0
DOCX/XLSX/PPTX (Office Open XML)
CODEBLOCK1
RTF (macOS)
CODEBLOCK2
EPUB
CODEBLOCK3
OpenDocument (ODT/ODS/ODP)
CODEBLOCK4
Scripts
extract_document.sh
Extracts text and metadata from any supported document format.
CODEBLOCK5
Output:
- - Text content to stdout
- Metadata as JSON comments
pdftoimages.sh
Converts PDF pages to images for OCR or visual processing.
CODEBLOCK6
Workflow
- 1. Identify format — Check file extension
- Extract text — Use appropriate tool
- Get metadata — Author, date, pages, etc.
- Process content — Summarize, search, transform
Notes
- - PDFs with scanned images need OCR (pdftoppm + tesseract)
- Encrypted PDFs require password
- Complex formatting may be lost in text extraction
- For tables in PDFs, consider tabula or camelot
文档处理器
从任何文档格式中提取文本、元数据和内容。
支持的格式
| 格式 | 扩展名 | 文本提取 | 元数据 | 转换 |
|---|
| PDF | .pdf | ✅ pdftotext | ✅ pdfinfo | ✅ pdftoppm |
| Word |
.docx | ✅ unzip + xml | ✅ | ✅ |
| Excel | .xlsx | ✅ unzip + xml | ✅ | ✅ |
| PowerPoint | .pptx | ✅ unzip + xml | ✅ | ✅ |
| EPUB | .epub | ✅ unzip + html | ✅ | ✅ |
| RTF | .rtf | ✅ textutil | ✅ | ✅ |
| OpenDocument | .odt, .ods, .odp | ✅ unzip + xml | ✅ | ✅ |
快速命令
PDF
bash
提取文本
pdftotext -layout input.pdf output.txt
获取元数据
pdfinfo input.pdf
转换为图像(用于OCR或查看)
pdftoppm -png input.pdf output_prefix
提取特定页面
pdftotext -f 5 -l 10 -layout input.pdf output.txt
DOCX/XLSX/PPTX(Office Open XML)
bash
从DOCX提取文本
unzip -p input.docx word/document.xml | sed s/<[^>]*>//g | tr -s \n
从XLSX提取文本(所有工作表)
unzip -p input.xlsx xl/sharedStrings.xml | sed s/<[^>]*>//g | tr -s \n
从PPTX提取文本
unzip -p input.pptx ppt/slides/
.xml | sed s/<[^>]>//g | tr -s \n
获取元数据
unzip -p input.docx docProps/core.xml
RTF(macOS)
bash
将RTF转换为纯文本
textutil -convert txt input.rtf -output output.txt
将RTF转换为HTML
textutil -convert html input.rtf -output output.html
EPUB
bash
提取并读取EPUB内容
unzip -l input.epub # 列出内容
unzip -p input.epub *.html | lynx -stdin -dump # 通过lynx获取文本
unzip -p input.epub
.xhtml | sed s/<[^>]>//g # 原始文本
OpenDocument(ODT/ODS/ODP)
bash
从ODT提取文本
unzip -p input.odt content.xml | sed s/<[^>]*>//g | tr -s \n
从ODS提取文本
unzip -p input.ods content.xml | sed s/<[^>]*>//g
获取元数据
unzip -p input.odt meta.xml
脚本
extract_document.sh
从任何支持的文档格式中提取文本和元数据。
bash
~/Dropbox/jarvis/skills/document-handler/scripts/extract_document.sh <文件>
输出:
pdftoimages.sh
将PDF页面转换为图像,用于OCR或视觉处理。
bash
~/Dropbox/jarvis/skills/document-handler/scripts/pdftoimages.sh <输出目录> [dpi]
工作流程
- 1. 识别格式 — 检查文件扩展名
- 提取文本 — 使用适当的工具
- 获取元数据 — 作者、日期、页数等
- 处理内容 — 摘要、搜索、转换
备注
- - 包含扫描图像的PDF需要OCR(pdftoppm + tesseract)
- 加密的PDF需要密码
- 复杂格式可能在文本提取中丢失
- 对于PDF中的表格,请考虑使用tabula或camelot