# Route: Add Comments ## Method 1: python-docx (Recommended — Simple) ```python from docx import Document from docx.oxml.ns import qn from docx.oxml import OxmlElement from datetime import datetime def add_comment(paragraph, comment_text, author="GLM", initials="G"): """Add a comment to an entire paragraph.""" # Create comment reference comment_id = str(hash(comment_text) % 10000) # Add to comments.xml (need to create if not exists) # ... complex XML manipulation required pass # Simpler approach: use python-docx-ng or manipulate XML directly ``` **Note**: python-docx has limited native comment support. For reliable results, use the OOXML method. ## Method 2: OOXML Direct Manipulation (Reliable) ### Step 1: Unpack ```bash mkdir work && cd work && unzip ../input.docx ``` ### Step 2: Create/update word/comments.xml ```xml This section needs more detail. ``` ### Step 3: Mark comment range in document.xml ```xml Text being commented on ``` ### Step 4: Update relationships In `word/_rels/document.xml.rels`, add: ```xml ``` ### Step 5: Update Content_Types In `[Content_Types].xml`, ensure: ```xml ``` ### Step 6: Pack ```bash zip -r ../output.docx . -x ".*" ``` ## When to Use Each Method | Scenario | Method | |----------|--------| | Add 1-2 simple comments | OOXML | | Batch review (many comments) | OOXML with Python script | | Comment on specific words | OOXML (precise range control) | | Quick annotation | python-docx if available |