Document Processing Guide
Work with office documents: PDF, Excel, Word, and PowerPoint.
Format Overview
| Format |
Extension |
Structure |
Best For |
| PDF |
.pdf |
Binary/text |
Reports, forms, archives |
| Excel |
.xlsx |
XML in ZIP |
Data, calculations, models |
| Word |
.docx |
XML in ZIP |
Text documents, contracts |
| PowerPoint |
.pptx |
XML in ZIP |
Presentations, slides |
Key concept: XLSX, DOCX, and PPTX are all ZIP archives containing XML files. You can unzip them to access raw content.
PDF Processing
PDF Tools
| Task |
Best Tool |
| Basic read/write |
pypdf |
| Text extraction |
pdfplumber |
| Table extraction |
pdfplumber |
| Create PDFs |
reportlab |
| OCR scanned PDFs |
pytesseract + pdf2image |
| Command line |
qpdf, pdftotext |
Common Operations
| Operation |
Approach |
| Merge |
Loop through files, add pages to writer |
| Split |
Create new writer per page |
| Extract tables |
Use pdfplumber, convert to DataFrame |
| Rotate |
Call .rotate(degrees) on page |
| Encrypt |
Use writer's .encrypt() method |
| OCR |
Convert to images, run pytesseract |
Excel Processing
Excel Tools
| Task |
Best Tool |
| Data analysis |
pandas |
| Formulas & formatting |
openpyxl |
| Simple CSV |
pandas |
| Financial models |
openpyxl |
Critical Rule: Use Formulas
| Approach |
Result |
| Wrong: Calculate in Python, write value |
Static number, breaks when data changes |
| Right: Write Excel formula |
Dynamic, recalculates automatically |
Financial Model Standards
| Convention |
Meaning |
| Blue text |
Hardcoded inputs |
| Black text |
Formulas |
| Green text |
Links to other sheets |
| Yellow fill |
Needs attention |
Common Formula Errors
| Error |
Cause |
| #REF! |
Invalid cell reference |
| #DIV/0! |
Division by zero |
| #VALUE! |
Wrong data type |
| #NAME? |
Unknown function name |
Word Processing
Word Tools
| Task |
Best Tool |
| Text extraction |
pandoc |
| Create new |
python-docx or docx-js |
| Simple edits |
python-docx |
| Tracked changes |
Direct XML editing |
Document Structure
| File |
Contains |
word/document.xml |
Main content |
word/comments.xml |
Comments |
word/media/ |
Images |
Tracked Changes (Redlining)
| Element |
XML Tag |
| Deletion |
<w:del><w:delText>...</w:delText></w:del> |
| Insertion |
<w:ins><w:t>...</w:t></w:ins> |
Key concept: For professional/legal documents, use tracked changes XML rather than replacing text directly.
PowerPoint Processing
PowerPoint Tools
| Task |
Best Tool |
| Text extraction |
markitdown |
| Create new |
pptxgenjs (JS) or python-pptx |
| Edit existing |
Direct XML or python-pptx |
Slide Structure
| Path |
Contains |
ppt/slides/slide{N}.xml |
Slide content |
ppt/notesSlides/ |
Speaker notes |
ppt/slideMasters/ |
Master templates |
ppt/media/ |
Images |
Design Principles
| Principle |
Guideline |
| Fonts |
Use web-safe: Arial, Helvetica, Georgia |
| Layout |
Two-column preferred, avoid vertical stacking |
| Hierarchy |
Size, weight, color for emphasis |
| Consistency |
Repeat patterns across slides |
Converting Between Formats
| Conversion |
Tool |
| Any → PDF |
LibreOffice headless |
| PDF → Images |
pdftoppm |
| DOCX → Markdown |
pandoc |
| Any → Text |
Appropriate extractor |
Best Practices
| Practice |
Why |
| Use formulas in Excel |
Dynamic calculations |
| Preserve formatting on edit |
Don't lose styles |
| Test output opens correctly |
Catch corruption early |
| Use tracked changes for contracts |
Audit trail |
| Extract to markdown for analysis |
Easier to process |
Common Packages
| Language |
Packages |
| Python |
pypdf, pdfplumber, openpyxl, python-docx, python-pptx |
| JavaScript |
docx, pptxgenjs |
| CLI |
pandoc, qpdf, pdftotext, libreoffice |
1---2name: document-processing3description: Use when working with "PDF", "Excel", "Word", "PowerPoint", "XLSX", "DOCX", "PPTX", "spreadsheets", "presentations", "extract text", "merge documents", "convert documents", or asking about "office document manipulation"4---5
6# Document Processing Guide
7
8Work with office documents: PDF, Excel, Word, and PowerPoint.
9
10---
11
12## Format Overview
13
14| Format | Extension | Structure | Best For |
15|--------|-----------|-----------|----------|
16| **PDF** | .pdf | Binary/text | Reports, forms, archives |
17| **Excel** | .xlsx | XML in ZIP | Data, calculations, models |
18| **Word** | .docx | XML in ZIP | Text documents, contracts |
19| **PowerPoint** | .pptx | XML in ZIP | Presentations, slides |
20
21**Key concept**: XLSX, DOCX, and PPTX are all ZIP archives containing XML files. You can unzip them to access raw content.
22
23---
24
25## PDF Processing
26
27### PDF Tools
28
29| Task | Best Tool |
30|------|-----------|
31| Basic read/write | pypdf |
32| Text extraction | pdfplumber |
33| Table extraction | pdfplumber |
34| Create PDFs | reportlab |
35| OCR scanned PDFs | pytesseract + pdf2image |
36| Command line | qpdf, pdftotext |
37
38### Common Operations
39
40| Operation | Approach |
41|-----------|----------|
42| **Merge** | Loop through files, add pages to writer |
43| **Split** | Create new writer per page |
44| **Extract tables** | Use pdfplumber, convert to DataFrame |
45| **Rotate** | Call `.rotate(degrees)` on page |
46| **Encrypt** | Use writer's `.encrypt()` method |
47| **OCR** | Convert to images, run pytesseract |
48
49---
50
51## Excel Processing
52
53### Excel Tools
54
55| Task | Best Tool |
56|------|-----------|
57| Data analysis | pandas |
58| Formulas & formatting | openpyxl |
59| Simple CSV | pandas |
60| Financial models | openpyxl |
61
62### Critical Rule: Use Formulas
63
64| Approach | Result |
65|----------|--------|
66| **Wrong**: Calculate in Python, write value | Static number, breaks when data changes |
67| **Right**: Write Excel formula | Dynamic, recalculates automatically |
68
69### Financial Model Standards
70
71| Convention | Meaning |
72|------------|---------|
73| Blue text | Hardcoded inputs |
74| Black text | Formulas |
75| Green text | Links to other sheets |
76| Yellow fill | Needs attention |
77
78### Common Formula Errors
79
80| Error | Cause |
81|-------|-------|
82| #REF! | Invalid cell reference |
83| #DIV/0! | Division by zero |
84| #VALUE! | Wrong data type |
85| #NAME? | Unknown function name |
86
87---
88
89## Word Processing
90
91### Word Tools
92
93| Task | Best Tool |
94|------|-----------|
95| Text extraction | pandoc |
96| Create new | python-docx or docx-js |
97| Simple edits | python-docx |
98| Tracked changes | Direct XML editing |
99
100### Document Structure
101
102| File | Contains |
103|------|----------|
104| `word/document.xml` | Main content |
105| `word/comments.xml` | Comments |
106| `word/media/` | Images |
107
108### Tracked Changes (Redlining)
109
110| Element | XML Tag |
111|---------|---------|
112| Deletion | `<w:del><w:delText>...</w:delText></w:del>` |
113| Insertion | `<w:ins><w:t>...</w:t></w:ins>` |
114
115**Key concept**: For professional/legal documents, use tracked changes XML rather than replacing text directly.
116
117---
118
119## PowerPoint Processing
120
121### PowerPoint Tools
122
123| Task | Best Tool |
124|------|-----------|
125| Text extraction | markitdown |
126| Create new | pptxgenjs (JS) or python-pptx |
127| Edit existing | Direct XML or python-pptx |
128
129### Slide Structure
130
131| Path | Contains |
132|------|----------|
133| `ppt/slides/slide{N}.xml` | Slide content |
134| `ppt/notesSlides/` | Speaker notes |
135| `ppt/slideMasters/` | Master templates |
136| `ppt/media/` | Images |
137
138### Design Principles
139
140| Principle | Guideline |
141|-----------|-----------|
142| Fonts | Use web-safe: Arial, Helvetica, Georgia |
143| Layout | Two-column preferred, avoid vertical stacking |
144| Hierarchy | Size, weight, color for emphasis |
145| Consistency | Repeat patterns across slides |
146
147---
148
149## Converting Between Formats
150
151| Conversion | Tool |
152|------------|------|
153| Any → PDF | LibreOffice headless |
154| PDF → Images | pdftoppm |
155| DOCX → Markdown | pandoc |
156| Any → Text | Appropriate extractor |
157
158---
159
160## Best Practices
161
162| Practice | Why |
163|----------|-----|
164| Use formulas in Excel | Dynamic calculations |
165| Preserve formatting on edit | Don't lose styles |
166| Test output opens correctly | Catch corruption early |
167| Use tracked changes for contracts | Audit trail |
168| Extract to markdown for analysis | Easier to process |
169
170## Common Packages
171
172| Language | Packages |
173|----------|----------|
174| **Python** | pypdf, pdfplumber, openpyxl, python-docx, python-pptx |
175| **JavaScript** | docx, pptxgenjs |
176| **CLI** | pandoc, qpdf, pdftotext, libreoffice |