$npx -y skills add mjunaidca/mjs-agent-skills --skill working-with-documentsCreates and edits Office documents: Word (.docx), PDF, and PowerPoint (.pptx). Use when working with document creation, PDF manipulation, presentation generation, tracked changes, or converting between formats.
| 1 | # Working with Documents |
| 2 | |
| 3 | ## Quick Reference |
| 4 | |
| 5 | | Format | Read | Create | Edit | |
| 6 | |--------|------|--------|------| |
| 7 | | DOCX | pandoc, python-docx | docx-js | OOXML (unpack/edit/pack) | |
| 8 | | PDF | pdfplumber, pypdf | reportlab | pypdf (merge/split) | |
| 9 | | PPTX | markitdown | html2pptx | OOXML (unpack/edit/pack) | |
| 10 | |
| 11 | ## Word Documents (.docx) |
| 12 | |
| 13 | ### Reading Content |
| 14 | |
| 15 | ```bash |
| 16 | # Convert to markdown (preserves structure) |
| 17 | pandoc document.docx -o output.md |
| 18 | |
| 19 | # With tracked changes visible |
| 20 | pandoc --track-changes=all document.docx -o output.md |
| 21 | ``` |
| 22 | |
| 23 | ### Creating New Documents |
| 24 | |
| 25 | Use **docx-js** (JavaScript): |
| 26 | |
| 27 | ```javascript |
| 28 | const { Document, Packer, Paragraph, TextRun } = require('docx'); |
| 29 | |
| 30 | const doc = new Document({ |
| 31 | sections: [{ |
| 32 | children: [ |
| 33 | new Paragraph({ |
| 34 | children: [ |
| 35 | new TextRun({ text: "Hello World", bold: true }), |
| 36 | ], |
| 37 | }), |
| 38 | ], |
| 39 | }], |
| 40 | }); |
| 41 | |
| 42 | Packer.toBuffer(doc).then(buffer => { |
| 43 | fs.writeFileSync("output.docx", buffer); |
| 44 | }); |
| 45 | ``` |
| 46 | |
| 47 | ### Editing Existing Documents (Tracked Changes) |
| 48 | |
| 49 | ```bash |
| 50 | # 1. Unpack |
| 51 | python ooxml/scripts/unpack.py document.docx unpacked/ |
| 52 | |
| 53 | # 2. Edit XML files in unpacked/word/document.xml |
| 54 | # Key files: |
| 55 | # - word/document.xml (main content) |
| 56 | # - word/comments.xml (comments) |
| 57 | # - word/media/ (images) |
| 58 | |
| 59 | # 3. Pack |
| 60 | python ooxml/scripts/pack.py unpacked/ edited.docx |
| 61 | ``` |
| 62 | |
| 63 | **Tracked changes XML pattern:** |
| 64 | ```xml |
| 65 | <!-- Deletion --> |
| 66 | <w:del><w:r><w:delText>old text</w:delText></w:r></w:del> |
| 67 | |
| 68 | <!-- Insertion --> |
| 69 | <w:ins><w:r><w:t>new text</w:t></w:r></w:ins> |
| 70 | ``` |
| 71 | |
| 72 | ## PDF Documents |
| 73 | |
| 74 | ### Reading PDFs |
| 75 | |
| 76 | ```python |
| 77 | import pdfplumber |
| 78 | |
| 79 | # Extract text |
| 80 | with pdfplumber.open("document.pdf") as pdf: |
| 81 | for page in pdf.pages: |
| 82 | print(page.extract_text()) |
| 83 | |
| 84 | # Extract tables |
| 85 | with pdfplumber.open("document.pdf") as pdf: |
| 86 | for page in pdf.pages: |
| 87 | tables = page.extract_tables() |
| 88 | for table in tables: |
| 89 | for row in table: |
| 90 | print(row) |
| 91 | ``` |
| 92 | |
| 93 | ### Creating PDFs |
| 94 | |
| 95 | ```python |
| 96 | from reportlab.lib.pagesizes import letter |
| 97 | from reportlab.platypus import SimpleDocTemplate, Paragraph |
| 98 | from reportlab.lib.styles import getSampleStyleSheet |
| 99 | |
| 100 | doc = SimpleDocTemplate("output.pdf", pagesize=letter) |
| 101 | styles = getSampleStyleSheet() |
| 102 | story = [ |
| 103 | Paragraph("Report Title", styles['Title']), |
| 104 | Paragraph("Body text goes here.", styles['Normal']), |
| 105 | ] |
| 106 | doc.build(story) |
| 107 | ``` |
| 108 | |
| 109 | ### Merging/Splitting PDFs |
| 110 | |
| 111 | ```python |
| 112 | from pypdf import PdfReader, PdfWriter |
| 113 | |
| 114 | # Merge |
| 115 | writer = PdfWriter() |
| 116 | for pdf_file in ["doc1.pdf", "doc2.pdf"]: |
| 117 | reader = PdfReader(pdf_file) |
| 118 | for page in reader.pages: |
| 119 | writer.add_page(page) |
| 120 | writer.write(open("merged.pdf", "wb")) |
| 121 | |
| 122 | # Split |
| 123 | reader = PdfReader("input.pdf") |
| 124 | for i, page in enumerate(reader.pages): |
| 125 | writer = PdfWriter() |
| 126 | writer.add_page(page) |
| 127 | writer.write(open(f"page_{i+1}.pdf", "wb")) |
| 128 | ``` |
| 129 | |
| 130 | ### Command-Line Tools |
| 131 | |
| 132 | ```bash |
| 133 | # Extract text |
| 134 | pdftotext input.pdf output.txt |
| 135 | pdftotext -layout input.pdf output.txt # Preserve layout |
| 136 | |
| 137 | # Merge with qpdf |
| 138 | qpdf --empty --pages file1.pdf file2.pdf -- merged.pdf |
| 139 | |
| 140 | # Split pages |
| 141 | qpdf input.pdf --pages . 1-5 -- pages1-5.pdf |
| 142 | ``` |
| 143 | |
| 144 | ## PowerPoint Presentations (.pptx) |
| 145 | |
| 146 | ### Reading Content |
| 147 | |
| 148 | ```bash |
| 149 | # Convert to markdown |
| 150 | python -m markitdown presentation.pptx |
| 151 | ``` |
| 152 | |
| 153 | ### Creating New Presentations |
| 154 | |
| 155 | Use **html2pptx** workflow: |
| 156 | |
| 157 | 1. Create HTML slides (720pt × 405pt for 16:9) |
| 158 | 2. Convert with html2pptx.js library |
| 159 | 3. Validate with thumbnail grid |
| 160 | |
| 161 | ```bash |
| 162 | # Create thumbnails for validation |
| 163 | python scripts/thumbnail.py output.pptx --cols 4 |
| 164 | ``` |
| 165 | |
| 166 | ### Editing Existing Presentations |
| 167 | |
| 168 | ```bash |
| 169 | # 1. Unpack |
| 170 | python ooxml/scripts/unpack.py presentation.pptx unpacked/ |
| 171 | |
| 172 | # Key files: |
| 173 | # - ppt/slides/slide1.xml, slide2.xml, etc. |
| 174 | # - ppt/notesSlides/ (speaker notes) |
| 175 | # - ppt/media/ (images) |
| 176 | |
| 177 | # 2. Edit XML |
| 178 | |
| 179 | # 3. Validate |
| 180 | python ooxml/scripts/validate.py unpacked/ --original presentation.pptx |
| 181 | |
| 182 | # 4. Pack |
| 183 | python ooxml/scripts/pack.py unpacked/ edited.pptx |
| 184 | ``` |
| 185 | |
| 186 | ### Rearranging Slides |
| 187 | |
| 188 | ```bash |
| 189 | # Duplicate, reorder, delete slides |
| 190 | python scripts/rearrange.py template.pptx output.pptx 0,3,3,5,7 |
| 191 | # Creates: slide 0, slide 3 (twice), slide 5, slide 7 |
| 192 | ``` |
| 193 | |
| 194 | ## Converting Between Formats |
| 195 | |
| 196 | ```bash |
| 197 | # DOCX/PPTX to PDF |
| 198 | soffice --headless --convert-to pdf document.docx |
| 199 | |
| 200 | # PDF to images |
| 201 | pdftoppm -jpeg -r 150 document.pdf page |
| 202 | # Creates: page-1.jpg, page-2.jpg, etc. |
| 203 | |
| 204 | # DOCX to Markdown |
| 205 | pandoc document.docx -o output.md |
| 206 | ``` |
| 207 | |
| 208 | ## OCR for Scanned Documents |
| 209 | |
| 210 | ```python |
| 211 | import pytesseract |
| 212 | from pdf2image import convert_from_path |
| 213 | |
| 214 | images = convert_from_path('scanned.pdf') |
| 215 | text = "" |
| 216 | for image in images: |
| 217 | text += pytesseract.image_to_string(image) |
| 218 | ``` |
| 219 | |
| 220 | ## Design Guidelines (Presentations) |
| 221 | |
| 222 | ### Color Palettes |
| 223 | |
| 224 | Pick 3-5 colors that work together: |
| 225 | |
| 226 | | Palette | Colors | |
| 227 | |---------|--------| |
| 228 | | Classic Blue | Navy #1C2833, Sla |