zcode-app-cli 3.3.5-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/README.md +642 -0
- package/bin/zcode.js +848 -0
- package/config.example.json +110 -0
- package/package.json +81 -0
- package/vendor/.node-bundle-meta.json +6 -0
- package/vendor/extraction.json +11 -0
- package/vendor/node_modules/@zcode/tui/dist/index.js +161875 -0
- package/vendor/node_modules/@zcode/tui/package.json +14 -0
- package/vendor/packages/android-emulator-plugin/.mcp.json +19 -0
- package/vendor/packages/android-emulator-plugin/.zcode-plugin/plugin.json +63 -0
- package/vendor/packages/android-emulator-plugin/README.md +134 -0
- package/vendor/packages/android-emulator-plugin/commands/android-dev.md +11 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/path.d.ts +4 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/path.js +17 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/result.d.ts +5 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/result.js +22 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/run.d.ts +18 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/run.js +99 -0
- package/vendor/packages/android-emulator-plugin/dist/mcp/server.d.ts +3 -0
- package/vendor/packages/android-emulator-plugin/dist/mcp/server.js +47607 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/app.d.ts +39 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/app.js +50 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/avd.d.ts +37 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/avd.js +185 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/build.d.ts +68 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/build.js +131 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/config.d.ts +7 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/config.js +29 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/device.d.ts +20 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/device.js +91 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/logs.d.ts +15 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/logs.js +31 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/preflight.d.ts +15 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/preflight.js +123 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project-template.d.ts +13 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project-template.js +211 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project.d.ts +33 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project.js +195 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.d.ts +14 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.js +73 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/sdk.d.ts +14 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/sdk.js +185 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/ui.d.ts +92 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/ui.js +146 -0
- package/vendor/packages/android-emulator-plugin/hooks/hooks.json +3 -0
- package/vendor/packages/android-emulator-plugin/package.json +35 -0
- package/vendor/packages/android-emulator-plugin/skills/android-dev/INSTALL_ENVIRONMENT.md +357 -0
- package/vendor/packages/android-emulator-plugin/skills/android-dev/SKILL.md +73 -0
- package/vendor/packages/android-emulator-plugin/templates/compose-app/README.md +5 -0
- package/vendor/packages/document-skills-plugin/.zcode-plugin/plugin.json +8 -0
- package/vendor/packages/document-skills-plugin/package.json +8 -0
- package/vendor/packages/document-skills-plugin/skills/docx/LICENSE.txt +13 -0
- package/vendor/packages/document-skills-plugin/skills/docx/SKILL.md +201 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/chart-templates.md +386 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/common-rules.md +419 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/decorations.md +537 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/design-system.md +1797 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-advanced.md +257 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-core.md +332 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/faq.md +323 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/math-formulas.md +276 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/ooxml.md +222 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/toc.md +264 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/comment.md +88 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/create.md +207 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/edit.md +115 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/format.md +120 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/read.md +114 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/academic.md +783 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/contract.md +463 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/copywriting.md +139 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/exam.md +698 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/official-doc.md +411 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/report.md +340 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/resume.md +534 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/__init__.py +1 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/add_toc_placeholders.py +749 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/document.py +1333 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/postcheck.py +807 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/comments.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtended.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsIds.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/people.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/utilities.py +374 -0
- package/vendor/packages/document-skills-plugin/skills/docx/setup.sh +177 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/LICENSE.txt +13 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/SKILL.md +919 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/academic.md +1058 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/creative.md +770 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/poster.md +702 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process-advanced.md +284 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process.md +319 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/report.md +1659 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/configs/components.md +153 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/configs/fonts.md +93 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/configs/visual_framework.md +263 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-academic.tex +130 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-altacv.tex +190 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/cover_validate.js +367 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/design_engine.py +2816 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2pdf-next.js +754 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2poster.js +256 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf.py +2959 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf_qa.py +901 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/poster_validate.py +1337 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/setup.sh +269 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/toc_validate.py +2075 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/charts.md +320 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover-backgrounds.md +384 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover.md +1442 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/fill-engine.md +527 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/geometry.md +142 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/overflow.md +630 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/pagination.md +367 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/palette.md +217 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/typography.md +20 -0
- package/vendor/packages/ios-simulator-plugin/.mcp.json +15 -0
- package/vendor/packages/ios-simulator-plugin/.zcode-plugin/plugin.json +34 -0
- package/vendor/packages/ios-simulator-plugin/README.md +111 -0
- package/vendor/packages/ios-simulator-plugin/commands/ios-dev.md +11 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/path.d.ts +4 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/path.js +18 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/result.d.ts +5 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/result.js +20 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/run.d.ts +17 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/run.js +83 -0
- package/vendor/packages/ios-simulator-plugin/dist/mcp/server.d.ts +3 -0
- package/vendor/packages/ios-simulator-plugin/dist/mcp/server.js +46833 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/build.d.ts +112 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/build.js +99 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/logs.d.ts +21 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/logs.js +26 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.d.ts +12 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.js +62 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/project.d.ts +35 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/project.js +288 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.d.ts +22 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.js +30 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/sim.d.ts +60 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/sim.js +116 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/ui.d.ts +57 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/ui.js +67 -0
- package/vendor/packages/ios-simulator-plugin/hooks/hooks.json +3 -0
- package/vendor/packages/ios-simulator-plugin/package.json +35 -0
- package/vendor/packages/ios-simulator-plugin/skills/ios-dev/SKILL.md +45 -0
- package/vendor/packages/ios-simulator-plugin/templates/swiftui-app/README.md +5 -0
- package/vendor/packages/restore-legacy-sessions-plugin/.zcode-plugin/plugin.json +9 -0
- package/vendor/packages/restore-legacy-sessions-plugin/README.md +35 -0
- package/vendor/packages/restore-legacy-sessions-plugin/commands/restore-legacy-sessions.md +11 -0
- package/vendor/packages/restore-legacy-sessions-plugin/package.json +8 -0
- package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/SKILL.md +92 -0
- package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/restore-conversation.mjs +648 -0
- package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/scan-legacy-sessions.mjs +422 -0
- package/vendor/packages/skill-creator-plugin/.zcode-plugin/plugin.json +8 -0
- package/vendor/packages/skill-creator-plugin/package.json +8 -0
- package/vendor/packages/skill-creator-plugin/skills/skill-creator/SKILL.md +159 -0
- package/vendor/packages/zcode-guide-plugin/.zcode-plugin/plugin.json +8 -0
- package/vendor/packages/zcode-guide-plugin/README.md +22 -0
- package/vendor/packages/zcode-guide-plugin/package.json +8 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-commands/SKILL.md +66 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-hooks/SKILL.md +66 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-mcp/SKILL.md +97 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-plugins/SKILL.md +59 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-skills/SKILL.md +61 -0
- package/vendor/packages/zcode-guide-plugin/skills/zcode-configuration-guide/SKILL.md +99 -0
- package/vendor/zcode.cjs +2926 -0
- package/zcode-runtime.lock.json +8 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# Process Brief: Advanced Reference
|
|
2
|
+
|
|
3
|
+
Edge-case tools and techniques. **Load only when the main `process.md` doesn't cover the task.**
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
Edge case
|
|
7
|
+
├─ No text extracted from PDF → §OCR Fallback
|
|
8
|
+
├─ PDF is encrypted/locked → §Encrypted PDFs
|
|
9
|
+
├─ PDF is corrupted/damaged → §Corrupted PDFs
|
|
10
|
+
├─ Need precise text coordinates → §pdfplumber Advanced
|
|
11
|
+
├─ Need fast rendering → §pypdfium2
|
|
12
|
+
├─ Advanced page extraction → §poppler-utils Advanced
|
|
13
|
+
├─ Complex page ranges / merge → §qpdf Page Manipulation
|
|
14
|
+
├─ Optimize file size → §qpdf Optimization
|
|
15
|
+
├─ Batch process many PDFs → §Batch Processing
|
|
16
|
+
└─ Memory issues with large PDF → §Performance Optimization
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
For basic operations (extract, merge, split, fill forms, convert), go back to `process.md`.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## §pypdfium2 (Apache/BSD License)
|
|
24
|
+
|
|
25
|
+
A Python binding for PDFium (Chromium's PDF library). Excellent for fast rendering and text extraction — serves as a PyMuPDF replacement.
|
|
26
|
+
|
|
27
|
+
#### Render PDF to Images
|
|
28
|
+
```python
|
|
29
|
+
import pypdfium2 as pdfium
|
|
30
|
+
|
|
31
|
+
pdf = pdfium.PdfDocument("document.pdf")
|
|
32
|
+
|
|
33
|
+
# Render single page
|
|
34
|
+
page = pdf[0]
|
|
35
|
+
bitmap = page.render(scale=2.0, rotation=0)
|
|
36
|
+
img = bitmap.to_pil()
|
|
37
|
+
img.save("page_1.png", "PNG")
|
|
38
|
+
|
|
39
|
+
# Batch render all pages
|
|
40
|
+
for i, page in enumerate(pdf):
|
|
41
|
+
bitmap = page.render(scale=1.5)
|
|
42
|
+
img = bitmap.to_pil()
|
|
43
|
+
img.save(f"page_{i+1}.jpg", "JPEG", quality=90)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### Extract Text with pypdfium2
|
|
47
|
+
```python
|
|
48
|
+
import pypdfium2 as pdfium
|
|
49
|
+
|
|
50
|
+
pdf = pdfium.PdfDocument("document.pdf")
|
|
51
|
+
for i, page in enumerate(pdf):
|
|
52
|
+
text = page.get_text()
|
|
53
|
+
print(f"Page {i+1}: {len(text)} chars")
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## §pdfplumber Advanced Features
|
|
57
|
+
|
|
58
|
+
#### Extract Text with Precise Coordinates
|
|
59
|
+
```python
|
|
60
|
+
import pdfplumber
|
|
61
|
+
|
|
62
|
+
with pdfplumber.open("document.pdf") as pdf:
|
|
63
|
+
page = pdf.pages[0]
|
|
64
|
+
|
|
65
|
+
# All characters with coordinates
|
|
66
|
+
for char in page.chars[:10]:
|
|
67
|
+
print(f"'{char['text']}' at x:{char['x0']:.1f} y:{char['y0']:.1f}")
|
|
68
|
+
|
|
69
|
+
# Extract text within a specific bounding box (left, top, right, bottom)
|
|
70
|
+
bbox_text = page.within_bbox((100, 100, 400, 200)).extract_text()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### Advanced Table Extraction with Custom Settings
|
|
74
|
+
```python
|
|
75
|
+
import pdfplumber
|
|
76
|
+
|
|
77
|
+
with pdfplumber.open("complex_table.pdf") as pdf:
|
|
78
|
+
page = pdf.pages[0]
|
|
79
|
+
|
|
80
|
+
table_settings = {
|
|
81
|
+
"vertical_strategy": "lines",
|
|
82
|
+
"horizontal_strategy": "lines",
|
|
83
|
+
"snap_tolerance": 3,
|
|
84
|
+
"intersection_tolerance": 15
|
|
85
|
+
}
|
|
86
|
+
tables = page.extract_tables(table_settings)
|
|
87
|
+
|
|
88
|
+
# Visual debugging
|
|
89
|
+
img = page.to_image(resolution=150)
|
|
90
|
+
img.save("debug_layout.png")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## §poppler-utils Advanced Features
|
|
96
|
+
|
|
97
|
+
### Extract Text with Bounding Box Coordinates
|
|
98
|
+
```bash
|
|
99
|
+
pdftotext -bbox-layout document.pdf output.xml
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Advanced Image Conversion
|
|
103
|
+
```bash
|
|
104
|
+
# High-resolution PNG
|
|
105
|
+
pdftoppm -png -r 300 document.pdf output_prefix
|
|
106
|
+
|
|
107
|
+
# Specific page range
|
|
108
|
+
pdftoppm -png -r 600 -f 1 -l 3 document.pdf high_res_pages
|
|
109
|
+
|
|
110
|
+
# JPEG with quality setting
|
|
111
|
+
pdftoppm -jpeg -jpegopt quality=85 -r 200 document.pdf jpeg_output
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Extract Embedded Images
|
|
115
|
+
```bash
|
|
116
|
+
pdfimages -all document.pdf images/img
|
|
117
|
+
pdfimages -list document.pdf
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## §qpdf Advanced Features
|
|
123
|
+
|
|
124
|
+
### Complex Page Manipulation
|
|
125
|
+
```bash
|
|
126
|
+
# Split into groups of N pages
|
|
127
|
+
qpdf --split-pages=3 input.pdf output_group_%02d.pdf
|
|
128
|
+
|
|
129
|
+
# Extract complex page ranges
|
|
130
|
+
qpdf input.pdf --pages input.pdf 1,3-5,8,10-end -- extracted.pdf
|
|
131
|
+
|
|
132
|
+
# Merge specific pages from multiple PDFs
|
|
133
|
+
qpdf --empty --pages doc1.pdf 1-3 doc2.pdf 5-7 doc3.pdf 2,4 -- combined.pdf
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### PDF Optimization and Repair
|
|
137
|
+
```bash
|
|
138
|
+
qpdf --linearize input.pdf optimized.pdf
|
|
139
|
+
qpdf --optimize-level=all input.pdf compressed.pdf
|
|
140
|
+
qpdf --check input.pdf
|
|
141
|
+
qpdf --fix-qdf damaged.pdf repaired.pdf
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Encryption and Decryption
|
|
145
|
+
```bash
|
|
146
|
+
qpdf --encrypt user_pass owner_pass 256 --print=none --modify=none -- input.pdf encrypted.pdf
|
|
147
|
+
qpdf --show-encryption encrypted.pdf
|
|
148
|
+
qpdf --password=secret123 --decrypt encrypted.pdf decrypted.pdf
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## §Encrypted PDFs
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from pypdf import PdfReader
|
|
157
|
+
|
|
158
|
+
try:
|
|
159
|
+
reader = PdfReader("encrypted.pdf")
|
|
160
|
+
if reader.is_encrypted:
|
|
161
|
+
reader.decrypt("password")
|
|
162
|
+
except Exception as e:
|
|
163
|
+
print(f"Failed to decrypt: {e}")
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Or via qpdf:
|
|
167
|
+
```bash
|
|
168
|
+
qpdf --password=secret123 --decrypt encrypted.pdf decrypted.pdf
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## §Corrupted PDFs
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
qpdf --check corrupted.pdf
|
|
177
|
+
qpdf --replace-input corrupted.pdf
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## §OCR Fallback for Scanned PDFs
|
|
183
|
+
|
|
184
|
+
When `pdfplumber` extracts 0 characters, the PDF is likely a scanned image:
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
import pytesseract
|
|
188
|
+
from pdf2image import convert_from_path
|
|
189
|
+
|
|
190
|
+
def extract_text_with_ocr(pdf_path):
|
|
191
|
+
images = convert_from_path(pdf_path)
|
|
192
|
+
text = ""
|
|
193
|
+
for i, image in enumerate(images):
|
|
194
|
+
text += pytesseract.image_to_string(image)
|
|
195
|
+
return text
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Prerequisites: `pip install pdf2image pytesseract` + install Tesseract OCR and poppler.
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## §Batch Processing with Error Handling
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
import os, glob
|
|
206
|
+
from pypdf import PdfReader, PdfWriter
|
|
207
|
+
import logging
|
|
208
|
+
|
|
209
|
+
logging.basicConfig(level=logging.INFO)
|
|
210
|
+
logger = logging.getLogger(__name__)
|
|
211
|
+
|
|
212
|
+
def batch_process_pdfs(input_dir, operation='merge'):
|
|
213
|
+
pdf_files = glob.glob(os.path.join(input_dir, "*.pdf"))
|
|
214
|
+
|
|
215
|
+
if operation == 'merge':
|
|
216
|
+
writer = PdfWriter()
|
|
217
|
+
for pdf_file in pdf_files:
|
|
218
|
+
try:
|
|
219
|
+
reader = PdfReader(pdf_file)
|
|
220
|
+
for page in reader.pages:
|
|
221
|
+
writer.add_page(page)
|
|
222
|
+
logger.info(f"Processed: {pdf_file}")
|
|
223
|
+
except Exception as e:
|
|
224
|
+
logger.error(f"Failed: {pdf_file}: {e}")
|
|
225
|
+
continue
|
|
226
|
+
with open("batch_merged.pdf", "wb") as output:
|
|
227
|
+
writer.write(output)
|
|
228
|
+
|
|
229
|
+
elif operation == 'extract_text':
|
|
230
|
+
for pdf_file in pdf_files:
|
|
231
|
+
try:
|
|
232
|
+
reader = PdfReader(pdf_file)
|
|
233
|
+
text = "".join(page.extract_text() for page in reader.pages)
|
|
234
|
+
output_file = pdf_file.replace('.pdf', '.txt')
|
|
235
|
+
with open(output_file, 'w', encoding='utf-8') as f:
|
|
236
|
+
f.write(text)
|
|
237
|
+
logger.info(f"Extracted: {pdf_file}")
|
|
238
|
+
except Exception as e:
|
|
239
|
+
logger.error(f"Failed: {pdf_file}: {e}")
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## §Performance Optimization
|
|
245
|
+
|
|
246
|
+
### Text Extraction
|
|
247
|
+
- `pdftotext -bbox-layout` is fastest for plain text
|
|
248
|
+
- Use pdfplumber for structured data and tables
|
|
249
|
+
- Avoid `pypdf.extract_text()` for very large documents
|
|
250
|
+
|
|
251
|
+
### Image Extraction
|
|
252
|
+
- `pdfimages` is much faster than rendering entire pages
|
|
253
|
+
- Use low resolution for previews, high resolution for final output
|
|
254
|
+
|
|
255
|
+
### Memory Management for Large PDFs
|
|
256
|
+
```python
|
|
257
|
+
def process_large_pdf(pdf_path, chunk_size=10):
|
|
258
|
+
reader = PdfReader(pdf_path)
|
|
259
|
+
total_pages = len(reader.pages)
|
|
260
|
+
|
|
261
|
+
for start_idx in range(0, total_pages, chunk_size):
|
|
262
|
+
end_idx = min(start_idx + chunk_size, total_pages)
|
|
263
|
+
writer = PdfWriter()
|
|
264
|
+
for i in range(start_idx, end_idx):
|
|
265
|
+
writer.add_page(reader.pages[i])
|
|
266
|
+
with open(f"chunk_{start_idx//chunk_size}.pdf", "wb") as output:
|
|
267
|
+
writer.write(output)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## Extended Tooling Inventory
|
|
273
|
+
|
|
274
|
+
| Library / Tool | Role | Licence |
|
|
275
|
+
|----------------|------|---------|
|
|
276
|
+
| pikepdf | Low-level PDF manipulation (forms, pages, metadata) | MPL-2.0 |
|
|
277
|
+
| pdfplumber | Content extraction (text, tables) | MIT |
|
|
278
|
+
| pypdfium2 | Fast rendering, text extraction (PyMuPDF alternative) | Apache/BSD |
|
|
279
|
+
| pypdf | Merge, split, crop, metadata, encryption | BSD |
|
|
280
|
+
| poppler-utils | CLI text/image extraction, rendering | GPL-2 |
|
|
281
|
+
| qpdf | Page manipulation, optimization, encryption, repair | Apache |
|
|
282
|
+
| pytesseract | OCR for scanned PDFs | Apache |
|
|
283
|
+
| pdf2image | PDF-to-image conversion via poppler | MIT |
|
|
284
|
+
| LibreOffice | Office format conversion engine | MPL-2.0 |
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
# Brief: PDF Processing
|
|
2
|
+
|
|
3
|
+
Work with existing PDFs: extract, merge, split, fill forms, convert formats, or **reformat** with a new design. Usually a Light triage path — except reformat, which escalates to Standard.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Decision Tree
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
User request
|
|
11
|
+
├─ "Extract text/tables/images" → §Extract
|
|
12
|
+
├─ "Merge/split/rotate/crop pages" → §Pages
|
|
13
|
+
├─ "Fill a form" → §Forms (check fillable first)
|
|
14
|
+
├─ "Read/write metadata" → §Metadata
|
|
15
|
+
├─ "Convert DOCX/PPTX/XLSX to PDF" → §Convert
|
|
16
|
+
│ └─ DOCX with TOC? → §DOCX Pipeline (5-step)
|
|
17
|
+
├─ "Redesign/reformat a document" → §Reformat
|
|
18
|
+
│ └─ With a reference template? → §Template-Guided Reformat
|
|
19
|
+
└─ Edge cases (OCR, encrypt, batch) → load briefs/process-advanced.md
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Environment Check
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" env.check
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Reports availability but does **not** auto-install. Required: Python 3, pikepdf, pdfplumber.
|
|
31
|
+
|
|
32
|
+
Entry point: `python3 "$PDF_SKILL_DIR/scripts/pdf.py" <group>.<action> [options]`
|
|
33
|
+
|
|
34
|
+
All commands return JSON on stdout (`{"status": "success", "data": {...}}`) or stderr (`{"status": "error", ...}`).
|
|
35
|
+
Exit codes: 0 = success, 1 = bad args, 2 = file not found, 3 = parse error, 4 = operation failed.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## §Extract
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Text (full or page range)
|
|
43
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" extract.text report.pdf
|
|
44
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" extract.text report.pdf -p 1-3
|
|
45
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" extract.text report.pdf -p 1,4,7
|
|
46
|
+
|
|
47
|
+
# Tables — returns structured JSON with page/rows/cols/data
|
|
48
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" extract.table report.pdf
|
|
49
|
+
|
|
50
|
+
# Images — dumps embedded rasters to directory
|
|
51
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" extract.image report.pdf -o ./images/
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## §Pages
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" pages.merge a.pdf b.pdf -o combined.pdf
|
|
60
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" pages.split book.pdf -o ./chapters/
|
|
61
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" pages.rotate doc.pdf 90 -o rotated.pdf
|
|
62
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" pages.rotate doc.pdf 180 -o rotated.pdf -p 1-3
|
|
63
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" pages.crop doc.pdf 50,50,550,750 -o trimmed.pdf
|
|
64
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" pages.clean doc.pdf -o cleaned.pdf
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## §Metadata
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" meta.get doc.pdf
|
|
73
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" meta.set doc.pdf -o out.pdf -d '{"Title": "Report", "Author": "Jane"}'
|
|
74
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" meta.brand doc.pdf -o branded.pdf
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Recognised keys: `Title`, `Author`, `Subject`, `Keywords`, `Creator`, `Producer`.
|
|
78
|
+
|
|
79
|
+
`meta.brand` adds standard branding metadata (producer, creator) in one step.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## §Forms
|
|
84
|
+
|
|
85
|
+
### Step 1 — Check if fillable
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" form.info input.pdf
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
If `has_fields: true` → **Fillable workflow**. If `false` → **Non-fillable workflow**.
|
|
92
|
+
|
|
93
|
+
### Fillable Workflow
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Inspect fields
|
|
97
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" form.info input.pdf
|
|
98
|
+
|
|
99
|
+
# Fill (auto-maps "true"/"false" for checkboxes)
|
|
100
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" form.fill input.pdf -o filled.pdf \
|
|
101
|
+
-d '{"name": "John", "agree": "true", "country": "US"}'
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Value rules:**
|
|
105
|
+
|
|
106
|
+
| Type | Value | Example |
|
|
107
|
+
|------|-------|---------|
|
|
108
|
+
| text | Free string | `"name": "Jane Doe"` |
|
|
109
|
+
| checkbox | `"true"` / `"false"` (auto-converts to PDF states) | `"agree": "true"` |
|
|
110
|
+
| radio | One of `radio_options[].value` | `"gender": "/Choice1"` |
|
|
111
|
+
| dropdown | One of `choice_options[].value` | `"country": "US"` |
|
|
112
|
+
|
|
113
|
+
For complex forms, use `form.detail` and `form.render` for deeper inspection:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" form.detail input.pdf -o fields.json # full field info (types, options, defaults)
|
|
117
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" form.render input.pdf -o ./pages/ # render pages as PNG for visual check
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Non-Fillable Workflow (Annotation-Based)
|
|
121
|
+
|
|
122
|
+
For PDFs without interactive fields (scanned forms, image-based). All four steps are mandatory.
|
|
123
|
+
|
|
124
|
+
**Step 1 — Render pages as PNG** (required):
|
|
125
|
+
```bash
|
|
126
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" form.render input.pdf -o ./pages/
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Step 2 — Create `fields.json`** with annotation regions.
|
|
130
|
+
|
|
131
|
+
To determine bbox coordinates: open the rendered PNG in an image viewer or use Python (`from PIL import Image; img = Image.open('page.png'); print(img.size)`) to get pixel dimensions. Then estimate [left, top, right, bottom] in pixels for each field by inspecting the image. The `dims` field must match the PNG dimensions exactly.
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"sheet": [
|
|
136
|
+
{
|
|
137
|
+
"pg": 1,
|
|
138
|
+
"dims": [1000, 1400],
|
|
139
|
+
"regions": [
|
|
140
|
+
{
|
|
141
|
+
"id": "last_name",
|
|
142
|
+
"hint": "Last name field",
|
|
143
|
+
"label": {"tag": "Last name", "bbox": [30, 125, 95, 142]},
|
|
144
|
+
"target": {"bbox": [100, 125, 280, 142]},
|
|
145
|
+
"ink": {"value": "Simpson", "size": 14, "color": "000000"}
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Schema: `pg` = 1-based page, `dims` = [w,h] in pixels, `label.bbox` / `target.bbox` = [left, top, right, bottom], `ink` = {value, size?, color?, font?}. Label and target boxes must NOT intersect.
|
|
154
|
+
|
|
155
|
+
**Step 3 — Validate bounding boxes** (required):
|
|
156
|
+
```bash
|
|
157
|
+
# Auto-check for intersections
|
|
158
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" form.check-bbox fields.json
|
|
159
|
+
|
|
160
|
+
# Visual validation (red=target, blue=label)
|
|
161
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" form.validate 1 fields.json page1.png validation.png
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Fix any issues, regenerate, re-check. Red rectangles must only cover input areas.
|
|
165
|
+
|
|
166
|
+
**Step 4 — Fill via annotations**:
|
|
167
|
+
```bash
|
|
168
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" form.annotate input.pdf fields.json -o filled.pdf
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## §Reformat
|
|
174
|
+
|
|
175
|
+
Take an existing document and rebuild it with a new visual design. Content is preserved; layout, typography, and visual treatment are rebuilt from scratch.
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
1. EXTRACT → Extract content from source (extract.text / extract.table / read directly)
|
|
179
|
+
2. STRUCTURE → Organize into sections (headings, body, tables, lists)
|
|
180
|
+
3. DELEGATE → Route to appropriate brief:
|
|
181
|
+
Structured → briefs/report.md (ReportLab)
|
|
182
|
+
Visual → briefs/creative.md (Playwright)
|
|
183
|
+
4. BUILD → Follow the delegated brief's full workflow
|
|
184
|
+
5. DELIVER → New PDF, same content, new design
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### §Template-Guided Reformat
|
|
188
|
+
|
|
189
|
+
When user provides a reference PDF to match:
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
1. ANALYZE → Extract design DNA from template:
|
|
193
|
+
- python3 "$PDF_SKILL_DIR/scripts/pdf.py" meta.get template.pdf (page size)
|
|
194
|
+
- python3 "$PDF_SKILL_DIR/scripts/pdf.py" extract.image template.pdf (color samples)
|
|
195
|
+
- python3 "$PDF_SKILL_DIR/scripts/pdf.py" extract.text template.pdf (text structure)
|
|
196
|
+
- pdftoppm -png -r 150 template.pdf preview (visual reference)
|
|
197
|
+
2. DOCUMENT → Record: page size, margins, colors, fonts, layout grid,
|
|
198
|
+
header/footer pattern, decorative elements
|
|
199
|
+
3. DELEGATE → Route to brief WITH design constraints (not brief defaults)
|
|
200
|
+
4. BUILD → Follow brief workflow, constrained to template DNA
|
|
201
|
+
5. COMPARE → pdftoppm both, visually compare side-by-side
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Key principles:**
|
|
205
|
+
- Match the spirit, not the pixels — exact replication from PDF is impractical
|
|
206
|
+
- Prefer original source files (.docx/.html/.tex) over PDF when available
|
|
207
|
+
- Declare font substitutions upfront; don't silently fall back
|
|
208
|
+
- Template provides design direction, not content — never leak placeholder text
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## §Convert
|
|
213
|
+
|
|
214
|
+
### Office → PDF (LibreOffice)
|
|
215
|
+
|
|
216
|
+
**Simple conversion** (no TOC needed):
|
|
217
|
+
```bash
|
|
218
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" convert.office input.docx -o output.pdf
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**When to use the 5-step DOCX Pipeline instead**: If the DOCX has (or should have) a Table of Contents, always use §DOCX Pipeline below. Signs: the document has 3+ headings, or the user mentions "table of contents" / "TOC", or the document already contains a TOC section. When in doubt, run `python3 "$PDF_SKILL_DIR/scripts/toc_validate.py" fix-docx input.docx -o fixed.docx` — if it returns `no_toc_needed`, a simple conversion is fine.
|
|
222
|
+
|
|
223
|
+
Or directly:
|
|
224
|
+
```bash
|
|
225
|
+
soffice --headless --convert-to pdf --outdir ./output input.docx
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Supported**: `.docx`, `.doc`, `.odt`, `.rtf`, `.pptx`, `.ppt`, `.xlsx`, `.xls`, `.ods`, `.csv`, `.html`
|
|
229
|
+
|
|
230
|
+
**macOS path**: `/Applications/LibreOffice.app/Contents/MacOS/soffice`
|
|
231
|
+
|
|
232
|
+
**Gotchas:**
|
|
233
|
+
- soffice allows only one instance at a time; close existing LibreOffice windows or use `--env:UserInstallation=file:///tmp/libreoffice_tmp`
|
|
234
|
+
- Missing Chinese fonts → squares. Ensure SimHei/SimSun are installed.
|
|
235
|
+
- Large files (>50MB) may take 1-2 min; set reasonable timeout
|
|
236
|
+
- soffice HTML→PDF is inferior to Playwright for complex CSS
|
|
237
|
+
|
|
238
|
+
**Priority**: Always prefer soffice for Office→PDF (preserves themes, layouts, master slides). Only fall back to python-pptx/python-docx + HTML + Playwright if soffice is unavailable — fidelity will be lower.
|
|
239
|
+
|
|
240
|
+
### Fallback: Spreadsheet → PDF without LibreOffice
|
|
241
|
+
|
|
242
|
+
Use openpyxl + HTML + Playwright. Let data shape drive layout:
|
|
243
|
+
|
|
244
|
+
| Factor | Decision |
|
|
245
|
+
|--------|----------|
|
|
246
|
+
| Columns ≤ 6 | Portrait |
|
|
247
|
+
| Columns > 6 | Landscape |
|
|
248
|
+
| Font size | Scale inversely with column count |
|
|
249
|
+
| Styling | Follow user requirements or source file style; if unspecified, use defaults from `typesetting/palette.md` |
|
|
250
|
+
|
|
251
|
+
### §DOCX Pipeline (5-Step with TOC)
|
|
252
|
+
|
|
253
|
+
For DOCX files that need TOC generation/correction. Required because LibreOffice `--headless` does not recalculate PAGEREF fields.
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
Step 1: soffice → Convert original DOCX to PDF (pass1)
|
|
257
|
+
Step 2: pages.clean → Remove blank pages from pass1
|
|
258
|
+
Step 3: fix-docx → Add/fix TOC with HYPERLINK + PAGEREF + bookmarks
|
|
259
|
+
Step 4: fix-pages → Correct TOC page numbers using pass1 as reference
|
|
260
|
+
Step 5: soffice → Convert final DOCX to PDF + pages.clean
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**Step 1 — Pass 1 Convert**:
|
|
264
|
+
```bash
|
|
265
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" convert.office input.docx -o pass1.pdf
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
**Step 2 — Clean Blank Pages**:
|
|
269
|
+
```bash
|
|
270
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" pages.clean pass1.pdf -o pass1_clean.pdf
|
|
271
|
+
```
|
|
272
|
+
If `blank_pages_removed == 0`, use pass1.pdf directly.
|
|
273
|
+
|
|
274
|
+
**Step 3 — Fix TOC**:
|
|
275
|
+
```bash
|
|
276
|
+
python3 "$PDF_SKILL_DIR/scripts/toc_validate.py" fix-docx input.docx -o fixed.docx
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Auto-detects and fixes: placeholder TOC, stale TOC (>50% drift), empty TOC, missing TOC (≥3 headings). Each entry gets `<w:hyperlink>` + `PAGEREF` + bookmarks for clickable PDF navigation.
|
|
280
|
+
|
|
281
|
+
Check output `action` field: `fixed` → use fixed.docx, `skipped` → use original, `no_toc_needed` → skip to Step 5 with pass1 PDF.
|
|
282
|
+
|
|
283
|
+
**Step 4 — Fix Page Numbers**:
|
|
284
|
+
```bash
|
|
285
|
+
python3 "$PDF_SKILL_DIR/scripts/toc_validate.py" fix-pages fixed.docx pass1_clean.pdf -o final.docx
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Corrects PAGEREF display text using actual page positions from pass1 + TOC page offset.
|
|
289
|
+
|
|
290
|
+
**Step 5 — Final Convert + Clean**:
|
|
291
|
+
```bash
|
|
292
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" convert.office final.docx -o output.pdf
|
|
293
|
+
python3 "$PDF_SKILL_DIR/scripts/pdf.py" pages.clean output.pdf -o output_clean.pdf
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Post-Conversion Validation (Optional)
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
python3 "$PDF_SKILL_DIR/scripts/toc_validate.py" check-conversion final.docx output_clean.pdf
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Issues caught: `CONV_TOC_LOST` (TOC disappeared), `CONV_HINT_LEAKED` (placeholder text in PDF), `CONV_HEADING_DRIFT` (heading count mismatch).
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Caveats
|
|
307
|
+
|
|
308
|
+
| Topic | Detail |
|
|
309
|
+
|-------|--------|
|
|
310
|
+
| Encrypted PDFs | Not supported. User must decrypt externally first. |
|
|
311
|
+
| < 50 MB | Instant |
|
|
312
|
+
| 50–200 MB | 1–2 minutes |
|
|
313
|
+
| > 200 MB | Split first, or extend timeout |
|
|
314
|
+
| Memory | ~2-3× input file size |
|
|
315
|
+
| Merge failure | Partial output may remain; delete and retry |
|
|
316
|
+
| Split failure | Some page files may exist; inspect output dir |
|
|
317
|
+
| Form fill | Original never modified; always writes new file |
|
|
318
|
+
|
|
319
|
+
For edge cases (OCR, batch processing, poppler-utils, qpdf, performance tuning), load `briefs/process-advanced.md`.
|