Document Q&A Extractor
Overview
Read documents in multiple formats (Word, PDF, PPT, Excel, TXT, images), extract key information, and generate a structured summary + Q&A markdown file. Supports single-file and batch processing.
Supported Formats
| Format | Extensions | Method |
|---|---|---|
| Word | .docx |
python-docx (paragraphs + tables) |
| Word (legacy) | .doc |
Best-effort olefile extraction; recommend converting to .docx |
.pdf |
pdfplumber (text + tables, page-by-page) | |
| PowerPoint | .pptx |
python-pptx (slide text + speaker notes + tables) |
| Excel | .xlsx |
openpyxl (all sheets, row-by-row) |
| Text | .txt .md .csv .json .xml .html .log etc. |
Direct read with encoding detection (utf-8/gbk/gb2312/latin-1/utf-16) |
| Images | .png .jpg .jpeg .gif .bmp .webp .tiff |
Flagged for Read tool (visual OCR) |
Workflow
Step 1: Collect File Paths
Gather all file paths from the user's request. Files may be provided as:
- Direct paths in the message
- Dragged-and-dropped files (use the paths as provided)
- Glob patterns to expand (e.g., *.pdf in a directory)
Verify all files exist before proceeding.
Step 2: Extract Text Content
Run the extraction script to pull raw text from all files:
C:/Users/Administrator/.workbuddy/binaries/python/envs/default/Scripts/python.exe scripts/extract_text.py <file1> <file2> ... --output extracted_text.txt
Important paths:
- Python interpreter: C:/Users/Administrator/.workbuddy/binaries/python/envs/default/Scripts/python.exe
- Script location: ~/.workbuddy/skills/doc-qa-extractor/scripts/extract_text.py
For image files (.png, .jpg, etc.): The script will flag them. Use the Read tool directly to view each image and extract text content visually.
If the script fails due to missing dependencies, install them:
C:/Users/Administrator/.workbuddy/binaries/python/envs/default/Scripts/pip.exe install python-docx pdfplumber python-pptx openpyxl
Step 3: Read the Extraction Guide
Before generating Q&A content, read references/extraction_guide.md for detailed standards on:
- Information extraction framework (what to look for)
- Summary writing standards
- Q&A generation principles and format
- Quality checklist
Step 4: Analyze and Extract Key Information
For each document's extracted text:
1. Identify the document type and structure
2. Extract key information across all dimensions (core thesis, facts, definitions, processes, decisions, risks, entities, timeline, metrics)
3. When processing multiple files, note cross-file themes and connections
Step 5: Generate Summary + Q&A Markdown
Use assets/qa_template.md as the output structure template. Generate the final markdown with:
- Cross-file overview (batch mode): Synthesize themes across all files
- Per-file sections: For each file, generate:
- File metadata (format, type, word count)
- One-sentence summary + 3-7 key bullet points
- 8-15 Q&A pairs (adjust based on document length) - Statistics section: File counts, success/fail counts, total Q&A pairs
Step 6: Save and Present Output
Save the generated markdown to a file (e.g., 文档问答摘要.md) in the user's workspace or a specified location. Use the present_files tool to present it.
Output Format Rules
- Language: Match the source document's language. Chinese documents → Chinese output. English documents → English output.
- Q&A format: Each Q&A pair uses
### Q{n}: {question}?with bold**A:**answer and a> 📌 来源:source attribution line. - No hallucination: If information is not in the document, state "文档中未提及此信息".
- Source attribution: Always cite the file name and section/page/paragraph for each answer.
- Summary conciseness: One-sentence summary gets straight to the point without filler phrases.
Example Usage Scenarios
Scenario 1: Single PDF
> User: "帮我提取这个 PDF 的要点,生成问答笔记"
> → Run extract_text.py on the PDF, analyze content, generate Q&A markdown
Scenario 2: Batch Word + PDF
> User: "把这三个文档的要点提取出来,做成问答"
> → Run extract_text.py on all three files, generate per-file summaries + cross-file overview + Q&A pairs
Scenario 3: Mixed formats with images
> User: "这个文件夹里的文档和截图都帮我整理成问答"
> → Run extract_text.py on text-based files, use Read tool for images, combine all into unified Q&A markdown
Dependencies
The extraction script requires these Python packages (installed in the managed venv):
- python-docx — Word .docx
- pdfplumber — PDF
- python-pptx — PowerPoint .pptx
- openpyxl — Excel .xlsx
If the venv does not exist, create it:
C:/Users/Administrator/.workbuddy/binaries/python/versions/3.13.12/python.exe -m venv C:/Users/Administrator/.workbuddy/binaries/python/envs/default
C:/Users/Administrator/.workbuddy/binaries/python/envs/default/Scripts/pip.exe install python-docx pdfplumber python-pptx openpyxl