LibreOffice Writer
Selective Reading Rule
Start with:
references/senior-master-standard.md
references/usage-routing.md
references/quality-checklist.md
Then load only the inherited docs, scripts, assets, or examples that match the user's actual task.
Overview
LibreOffice Writer skill for creating, editing, converting, and automating document workflows using the native ODT (OpenDocument Text) format.
When to Use This Skill
Use this skill when:
- Creating new documents in ODT format
- Converting documents between formats (ODT <-> DOCX, PDF, HTML, RTF, TXT)
- Automating document generation workflows
- Performing batch document operations
- Creating templates and standardized document formats
Core Capabilities
1. Document Creation
- Create new ODT documents from scratch
- Generate documents from templates
- Create mail merge documents
- Build forms with fillable fields
2. Format Conversion
- ODT to other formats: DOCX, PDF, HTML, RTF, TXT, EPUB
- Other formats to ODT: DOCX, DOC, RTF, HTML, TXT
- Batch conversion of multiple documents
3. Document Automation
- Template-based document generation
- Mail merge with data sources (CSV, spreadsheet, database)
- Batch document processing
- Automated report generation
4. Content Manipulation
- Text extraction and insertion
- Style management and application
- Table creation and manipulation
- Header/footer management
5. Integration
- Command-line automation via soffice
- Python scripting with UNO
- Integration with workflow automation tools
Workflows
Creating a New Document
Method 1: Command-Line
soffice --writer template.odt
Method 2: Python with UNO
import uno
def create_document():
local_ctx = uno.getComponentContext()
resolver = local_ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", local_ctx
)
ctx = resolver.resolve(
"uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext"
)
smgr = ctx.ServiceManager
doc = smgr.createInstanceWithContext("com.sun.star.text.TextDocument", ctx)
text = doc.Text
cursor = text.createTextCursor()
text.insertString(cursor, "Hello from LibreOffice Writer!", 0)
doc.storeToURL("file:///path/to/document.odt", ())
doc.close(True)
Method 3: Using odfpy
from odf.opendocument import OpenDocumentText
from odf.text import P, H
doc = OpenDocumentText()
h1 = H(outlinelevel='1', text='Document Title')
doc.text.appendChild(h1)
doc.save("document.odt")
Converting Documents
# ODT to DOCX
soffice --headless --convert-to docx document.odt
# ODT to PDF
soffice --headless --convert-to pdf document.odt
# DOCX to ODT
soffice --headless --convert-to odt document.docx
# Batch convert
for file in *.odt; do
soffice --headless --convert-to pdf "$file"
done
Template-Based Generation
import subprocess
import tempfile
from pathlib import Path
def generate_from_template(template_path, variables, output_path):
with tempfile.TemporaryDirectory() as tmpdir:
subprocess.run(['unzip', '-q', template_path, '-d', tmpdir])
content_file = Path(tmpdir) / 'content.xml'
content = content_file.read_text()
for key, value in variables.items():
content = content.replace(f'${{{key}}}', str(value))
content_file.write_text(content)
subprocess.run(['zip', '-rq', output_path, '.'], cwd=tmpdir)
return output_path
Format Conversion Reference
Supported Input Formats
- ODT (native), DOCX, DOC, RTF, HTML, TXT, EPUB
Supported Output Formats
- ODT, DOCX, PDF, PDF/A, HTML, RTF, TXT, EPUB
Command-Line Reference
soffice --headless
soffice --headless --convert-to <format> <file>
soffice --writer # Writer
soffice --calc # Calc
soffice --impress # Impress
soffice --draw # Draw
Python Libraries
pip install odfpy # ODF manipulation
pip install ezodf # Easier ODF handling
Best Practices
- Use styles for consistency
- Create templates for recurring documents
- Ensure accessibility (heading hierarchy, alt text)
- Fill document metadata
- Store ODT source files in version control
- Test conversions thoroughly
- Embed fonts for PDF distribution
- Handle conversion failures gracefully
- Log automation operations
- Clean temporary files
Troubleshooting
Cannot open socket
killall soffice.bin
soffice --headless --accept="socket,host=localhost,port=8100;urp;"
Conversion Quality Issues
soffice --headless --convert-to pdf:writer_pdf_Export document.odt
Resources
Related Skills
- calc
- impress
- draw
- base
- docx-official
- pdf-official
- workflow-automation
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
1---2name: writer3description: ALWAYS use this when the request matches Writer: Document creation, format conversion (ODT/DOCX/PDF), mail merge, and automation with LibreOffice Writer.4---56# LibreOffice Writer78## Selective Reading Rule910Start with:1112- `references/senior-master-standard.md`13- `references/usage-routing.md`14- `references/quality-checklist.md`1516Then load only the inherited docs, scripts, assets, or examples that match the user's actual task.1718## Overview1920LibreOffice Writer skill for creating, editing, converting, and automating document workflows using the native ODT (OpenDocument Text) format.2122## When to Use This Skill2324Use this skill when:25- Creating new documents in ODT format26- Converting documents between formats (ODT <-> DOCX, PDF, HTML, RTF, TXT)27- Automating document generation workflows28- Performing batch document operations29- Creating templates and standardized document formats3031## Core Capabilities3233### 1. Document Creation34- Create new ODT documents from scratch35- Generate documents from templates36- Create mail merge documents37- Build forms with fillable fields3839### 2. Format Conversion40- ODT to other formats: DOCX, PDF, HTML, RTF, TXT, EPUB41- Other formats to ODT: DOCX, DOC, RTF, HTML, TXT42- Batch conversion of multiple documents4344### 3. Document Automation45- Template-based document generation46- Mail merge with data sources (CSV, spreadsheet, database)47- Batch document processing48- Automated report generation4950### 4. Content Manipulation51- Text extraction and insertion52- Style management and application53- Table creation and manipulation54- Header/footer management5556### 5. Integration57- Command-line automation via soffice58- Python scripting with UNO59- Integration with workflow automation tools6061## Workflows6263### Creating a New Document6465#### Method 1: Command-Line66```bash67soffice --writer template.odt68```6970#### Method 2: Python with UNO71```python72import uno7374def create_document():75 local_ctx = uno.getComponentContext()76 resolver = local_ctx.ServiceManager.createInstanceWithContext(77 "com.sun.star.bridge.UnoUrlResolver", local_ctx78 )79 ctx = resolver.resolve(80 "uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext"81 )82 smgr = ctx.ServiceManager83 doc = smgr.createInstanceWithContext("com.sun.star.text.TextDocument", ctx)84 text = doc.Text85 cursor = text.createTextCursor()86 text.insertString(cursor, "Hello from LibreOffice Writer!", 0)87 doc.storeToURL("file:///path/to/document.odt", ())88 doc.close(True)89```9091#### Method 3: Using odfpy92```python93from odf.opendocument import OpenDocumentText94from odf.text import P, H9596doc = OpenDocumentText()97h1 = H(outlinelevel='1', text='Document Title')98doc.text.appendChild(h1)99doc.save("document.odt")100```101102### Converting Documents103104```bash105# ODT to DOCX106soffice --headless --convert-to docx document.odt107108# ODT to PDF109soffice --headless --convert-to pdf document.odt110111# DOCX to ODT112soffice --headless --convert-to odt document.docx113114# Batch convert115for file in *.odt; do116 soffice --headless --convert-to pdf "$file"117done118```119120### Template-Based Generation121```python122import subprocess123import tempfile124from pathlib import Path125126def generate_from_template(template_path, variables, output_path):127 with tempfile.TemporaryDirectory() as tmpdir:128 subprocess.run(['unzip', '-q', template_path, '-d', tmpdir])129 content_file = Path(tmpdir) / 'content.xml'130 content = content_file.read_text()131 for key, value in variables.items():132 content = content.replace(f'${{{key}}}', str(value))133 content_file.write_text(content)134 subprocess.run(['zip', '-rq', output_path, '.'], cwd=tmpdir)135 return output_path136```137138## Format Conversion Reference139140### Supported Input Formats141- ODT (native), DOCX, DOC, RTF, HTML, TXT, EPUB142143### Supported Output Formats144- ODT, DOCX, PDF, PDF/A, HTML, RTF, TXT, EPUB145146## Command-Line Reference147148```bash149soffice --headless150soffice --headless --convert-to <format> <file>151soffice --writer # Writer152soffice --calc # Calc153soffice --impress # Impress154soffice --draw # Draw155```156157## Python Libraries158159```bash160pip install odfpy # ODF manipulation161pip install ezodf # Easier ODF handling162```163164## Best Practices1651661. Use styles for consistency1672. Create templates for recurring documents1683. Ensure accessibility (heading hierarchy, alt text)1694. Fill document metadata1705. Store ODT source files in version control1716. Test conversions thoroughly1727. Embed fonts for PDF distribution1738. Handle conversion failures gracefully1749. Log automation operations17510. Clean temporary files176177## Troubleshooting178179### Cannot open socket180```bash181killall soffice.bin182soffice --headless --accept="socket,host=localhost,port=8100;urp;"183```184185### Conversion Quality Issues186```bash187soffice --headless --convert-to pdf:writer_pdf_Export document.odt188```189190## Resources191192- [LibreOffice Writer Guide](https://documentation.libreoffice.org/)193- [LibreOffice SDK](https://wiki.documentfoundation.org/Documentation/DevGuide)194- [UNO API Reference](https://api.libreoffice.org/)195- [odfpy](https://pypi.org/project/odfpy/)196197## Related Skills198199- calc200- impress201- draw202- base203- docx-official204- pdf-official205- workflow-automation206207## Limitations208- Use this skill only when the task clearly matches the scope described above.209- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.210- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.