---
name: Document Creation
description: Create professional documents — PDF, Word, Excel, PowerPoint
triggers: pdf, document, report, letter, deck, slides, presentation, powerpoint, pptx, excel, xlsx, spreadsheet, docx, create document, dokument erstellen, bericht erstellen, dokument schreiben, anschreiben, vorlage, präsentation, tabelle, brief schreiben, write a letter, word-dokument, word document
priority: 4
category: productivity
---

# Document Creation Skill

Pick the format the recipient will actually work in:

| They will… | Build |
|---|---|
| read it, print it, forward it | **PDF** (HTML → PDF) |
| present it, edit slides | **PPTX** (python-pptx) |
| filter, sort, recalculate | **XLSX** (openpyxl) |
| keep writing in it | **DOCX** (python-docx) |

A PDF of a table someone asked to *work with* is a near-miss. So is a deck someone
wanted as a one-pager. Ask once if it is genuinely unclear; otherwise choose.

## Workflow

1. **Clarify** format and audience — internal note or client-facing?
2. **Write the content YOURSELF** — you are the language model. Never leave placeholders.
3. **Build** with the tool for that format (below)
4. **Look at it** — render to image and actually inspect it before sending (see Verify)
5. **Deliver** the file

---

## PDF — HTML + Chrome/Playwright

Best when layout is prose-like and nobody needs to edit it.

```bash
cat > /tmp/document.html << 'EOF'
<!DOCTYPE html>
<html><head><meta charset="utf-8">
<style>
  body { font-family: 'Segoe UI', system-ui, sans-serif; max-width: 210mm; margin: 0 auto;
         padding: 20mm; line-height: 1.6; color: #333; }
  h1 { color: #1a1a2e; border-bottom: 2px solid #e2b04a; padding-bottom: 8px; }
  table { width: 100%; border-collapse: collapse; margin: 1em 0; }
  th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
  th { background: #f5f5f5; }
</style></head><body>
<!-- CONTENT HERE -->
</body></html>
EOF

npx playwright-core pdf /tmp/document.html /tmp/document.pdf --format=A4 2>/dev/null || \
  wkhtmltopdf --page-size A4 /tmp/document.html /tmp/document.pdf 2>/dev/null
```

---

## PPTX — python-pptx, drawn not templated

`pip install python-pptx` · Do **not** convert HTML to PPTX — the result looks converted.
Draw the slide instead. The approach below is what separates a deck that looks designed
from one that looks generated.

### Set up a working space you can think in

Design in pixels (like a web canvas), emit points. A 1280×720 canvas maps to a
960×540 pt slide — factor **0.75**.

```python
from pptx import Presentation
from pptx.util import Pt
from pptx.dml.color import RGBColor
from pptx.enum.shapes import MSO_SHAPE
from pptx.oxml.ns import qn

K = 0.75                      # 1280x720 px canvas -> 960x540 pt slide (16:9)
def P(v): return Pt(v * K)

prs = Presentation()
prs.slide_width, prs.slide_height = Pt(960), Pt(540)

def rgb(h):
    h = h.lstrip('#')
    return RGBColor(int(h[0:2],16), int(h[2:4],16), int(h[4:6],16))
```

### Two fixes python-pptx does not give you

Without these, every shape carries the default theme shadow and you cannot do
translucent fills — the two things that make a deck look like clip-art.

```python
def _noshadow(sp):
    """Shapes ship with a theme style + shadow. Strip both, or it looks cheap."""
    el = sp._element
    style = el.find(qn('p:style'))
    if style is not None:
        el.remove(style)
    spPr = el.find(qn('p:spPr'))
    if spPr is not None:
        for e in spPr.findall(qn('a:effectLst')):
            spPr.remove(e)
        spPr.append(spPr.makeelement(qn('a:effectLst'), {}))   # explicitly: no effects

def _alpha(srgb, opacity):
    """Transparency has no python-pptx API — it only exists in the XML."""
    srgb.append(srgb.makeelement(qn('a:alpha'), {'val': str(int(opacity * 100000))}))

def fill(sp, color, alpha=None):
    if color is None:
        sp.fill.background(); return
    sp.fill.solid(); sp.fill.fore_color.rgb = color
    if alpha is not None:
        # `_xFill` is private to python-pptx (verified against 1.0.2). There is no
        # public API for transparency — but if a future version renames it, this
        # raises AttributeError mid-build. Pin the version if that matters to you.
        srgb = sp.fill.fore_color._xFill.find(qn('a:srgbClr'))
        if srgb is None:
            # Silent fallback would render fully opaque and look "almost right",
            # which the render check does not reliably catch. Fail loudly instead.
            raise RuntimeError("transparency unavailable: python-pptx fill internals changed")
        _alpha(srgb, alpha)
```

### Build primitives once, then compose

Write `rect()`, `line()`, `oval()`, `textbox()` once; then build `card()`, `bullets()`,
`kicker()`, `footer()` on top and lay slides out from those. Every shape goes through
`_noshadow()`.

```python
def rect(s, x, y, w, h, color, rx=0, alpha=None):
    shape = MSO_SHAPE.ROUNDED_RECTANGLE if rx else MSO_SHAPE.RECTANGLE
    sp = s.shapes.add_shape(shape, P(x), P(y), P(max(w, 0.2)), P(max(h, 0.2)))
    if rx:
        # Choosing ROUNDED_RECTANGLE alone leaves the adjustment list empty, and
        # PowerPoint then applies its own default radius — your rx does nothing.
        # The adjustment is a FRACTION of the shorter side, so convert.
        sp.adjustments[0] = min(rx / max(min(w, h), 0.2), 0.5)
    sp.line.fill.background(); _noshadow(sp); fill(sp, color, alpha)
    return sp
```

### Charts: draw them

PowerPoint's chart objects fight your layout and drag a hidden worksheet along. For a
bar, a stacked bar or a progress track, draw rectangles — full control over spacing,
labels and colour, and it renders identically everywhere.

### Slide rules that carry a deck

- **One message per slide.** The headline states it; the slide shows it.
- **Fixed grid:** same margins, same baseline, same kicker position on every slide.
- **Three colours plus ink.** A brand colour, an accent, a muted tone — and near-black text.
- **Real numbers**, formatted for the locale (`1.234,50 €` for DE).
- **Speaker notes** for anything you would otherwise cram onto the slide:
  `slide.notes_slide.notes_text_frame.text = "..."`
- **Save it:** `prs.save("/tmp/deck.pptx")`. Nothing exists on disk until you do, and the
  Verify step below needs that file.
- **Inheriting a corporate master:** python-pptx opens `.pptx` only — a `.potx` raises
  `ValueError: ... is not a PowerPoint file`. Ask for it as `.pptx`, or convert it once
  (`soffice --headless --convert-to pptx master.potx`), then `Presentation("master.pptx")`
  and add slides from its layouts. Check afterwards that the layouts you need survived the
  conversion; brand, fonts and placeholders come along, the layout *count* need not.
  **Recompute the scale factor when you do:** opening a master inherits ITS slide size and
  overrides the 960x540 set earlier. Many corporate masters are 4:3 (720x540 pt), and with
  the old `K = 0.75` every shape past x≈960 px would land off the slide:
  `K = prs.slide_width.pt / 1280.0`

---

## XLSX — openpyxl, a workbook not a CSV

`pip install openpyxl` · If someone asked for Excel, they want to *work* in it.

```python
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
from openpyxl.utils import get_column_letter
from openpyxl.formatting.rule import CellIsRule
from openpyxl.worksheet.datavalidation import DataValidation

wb = Workbook(); ws = wb.active; ws.title = "Overview"

ws["A1"] = "Item"; ws["B1"] = "Amount"
for c in ("A1", "B1"):
    ws[c].font = Font(bold=True, color="FFFFFF")
    ws[c].fill = PatternFill("solid", fgColor="10264E")
    ws[c].alignment = Alignment(horizontal="left", vertical="center")

ws["B2"] = 19000
ws["B2"].number_format = '#,##0.00 "€"'        # a number, not a string
ws["B10"] = "=SUM(B2:B9)"                       # a real formula
ws["B10"].number_format = '#,##0.00 "€"'        # the total needs the format too
ws.freeze_panes = "A2"                          # header stays visible
ws.column_dimensions["A"].width = 38            # labels
ws.column_dimensions["B"].width = 18            # NUMBER columns too — see note below
ws.conditional_formatting.add("B2:B9",
    CellIsRule(operator="lessThan", formula=["0"], font=Font(color="E5554F")))
ws.add_data_validation(dv := DataValidation(type="list", formula1='"open,done"'))
dv.add("C2:C9")                                 # dropdown instead of free text
wb.save("/tmp/report.xlsx")
```

Non-negotiables: numbers as numbers with `number_format` (**the total cell too** — it is
the one everybody reads), totals as **formulas**, `freeze_panes` on the header, column
widths set — **including the number columns**. A currency format widens the cell content;
too narrow and Excel shows `###`, which in an exported PDF becomes a row of hashes where
your total should be. Found exactly that way: the first render of this example showed
`###` instead of the sum. Charts via
`openpyxl.chart` (`BarChart`, `DoughnutChart`, `Reference`) are real Excel charts and
stay live when the data changes.

---

## DOCX — python-docx

`pip install python-docx` · For letters and reports the recipient will keep editing.
Use real styles (`doc.add_heading`, `doc.add_paragraph(style=...)`) rather than manual
bold — that keeps their navigation pane and table of contents working.

---

## Verify — look at what you built

**Mandatory for anything client-facing.** You cannot judge a deck by the code that made it.

```bash
soffice --headless --convert-to pdf --outdir /tmp /tmp/deck.pptx
pdftoppm -png -r 110 /tmp/deck.pdf /tmp/slide      # → /tmp/slide-1.png, -2.png …
```

Then **read those images** and check: text clipped? overlaps? contrast too low?
placeholder left in? numbers right? Fix and re-render.

Two things worth knowing:

- **A rendered total is not a checked total.** LibreOffice prints the *cached* result
  stored in the file; it does not recalculate on export, not even with the
  `fullCalcOnLoad` flag openpyxl already writes. A workbook you just built shows the right
  sum only because openpyxl leaves that cache empty, so LibreOffice has to compute it. Two
  ways to lose that: a file that came out of Excel brings its own cached numbers, and
  `load_workbook(..., data_only=True)` reads them — saving that workbook keeps the numbers
  and **drops the formulas**. Both still render a clean-looking PDF. Check the arithmetic.
- **`qlmanage -t` renders the first slide only.** Measured on a three-slide deck: one
  thumbnail from `qlmanage`, three pages from `pdftoppm` on the exported PDF. Fine for a
  glance at the title slide, useless as the verify step — you would approve a deck having
  seen a third of it.

No LibreOffice installed? **Building still works — only the visual check is missing.**
Say so once, deliver the file, and name the install (`brew install --cask libreoffice`,
`apt install libreoffice`). Never claim you cannot produce the document.

---

## Guidelines

- **A4** for European documents, Letter for US
- **Dates** in the user's locale (DD.MM.YYYY for DE)
- **Page breaks** — `break-inside: avoid` on logical blocks (HTML)
- **Filenames** that sort and say what they are: `Topic_2026-08-21.pptx`
- **Never ship a placeholder.** No "Lorem ipsum", no "TODO", no "<insert figure>"
