LibreOffice Writer
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 enprojectnment-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: Document creation, format conversion (ODT/DOCX/PDF), mail merge, and automation with LibreOffice Writer.4---56# LibreOffice Writer78## Overview910LibreOffice Writer skill for creating, editing, converting, and automating document workflows using the native ODT (OpenDocument Text) format.1112## When to Use This Skill1314Use this skill when:15- Creating new documents in ODT format16- Converting documents between formats (ODT <-> DOCX, PDF, HTML, RTF, TXT)17- Automating document generation workflows18- Performing batch document operations19- Creating templates and standardized document formats2021## Core Capabilities2223### 1. Document Creation24- Create new ODT documents from scratch25- Generate documents from templates26- Create mail merge documents27- Build forms with fillable fields2829### 2. Format Conversion30- ODT to other formats: DOCX, PDF, HTML, RTF, TXT, EPUB31- Other formats to ODT: DOCX, DOC, RTF, HTML, TXT32- Batch conversion of multiple documents3334### 3. Document Automation35- Template-based document generation36- Mail merge with data sources (CSV, spreadsheet, database)37- Batch document processing38- Automated report generation3940### 4. Content Manipulation41- Text extraction and insertion42- Style management and application43- Table creation and manipulation44- Header/footer management4546### 5. Integration47- Command-line automation via soffice48- Python scripting with UNO49- Integration with workflow automation tools5051## Workflows5253### Creating a New Document5455#### Method 1: Command-Line56```bash57soffice --writer template.odt58```5960#### Method 2: Python with UNO61```python62import uno6364def create_document():65 local_ctx = uno.getComponentContext()66 resolver = local_ctx.ServiceManager.createInstanceWithContext(67 "com.sun.star.bridge.UnoUrlResolver", local_ctx68 )69 ctx = resolver.resolve(70 "uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext"71 )72 smgr = ctx.ServiceManager73 doc = smgr.createInstanceWithContext("com.sun.star.text.TextDocument", ctx)74 text = doc.Text75 cursor = text.createTextCursor()76 text.insertString(cursor, "Hello from LibreOffice Writer!", 0)77 doc.storeToURL("file:///path/to/document.odt", ())78 doc.close(True)79```8081#### Method 3: Using odfpy82```python83from odf.opendocument import OpenDocumentText84from odf.text import P, H8586doc = OpenDocumentText()87h1 = H(outlinelevel='1', text='Document Title')88doc.text.appendChild(h1)89doc.save("document.odt")90```9192### Converting Documents9394```bash95# ODT to DOCX96soffice --headless --convert-to docx document.odt9798# ODT to PDF99soffice --headless --convert-to pdf document.odt100101# DOCX to ODT102soffice --headless --convert-to odt document.docx103104# Batch convert105for file in *.odt; do106 soffice --headless --convert-to pdf "$file"107done108```109110### Template-Based Generation111```python112import subprocess113import tempfile114from pathlib import Path115116def generate_from_template(template_path, variables, output_path):117 with tempfile.TemporaryDirectory() as tmpdir:118 subprocess.run(['unzip', '-q', template_path, '-d', tmpdir])119 content_file = Path(tmpdir) / 'content.xml'120 content = content_file.read_text()121 for key, value in variables.items():122 content = content.replace(f'${{{key}}}', str(value))123 content_file.write_text(content)124 subprocess.run(['zip', '-rq', output_path, '.'], cwd=tmpdir)125 return output_path126```127128## Format Conversion Reference129130### Supported Input Formats131- ODT (native), DOCX, DOC, RTF, HTML, TXT, EPUB132133### Supported Output Formats134- ODT, DOCX, PDF, PDF/A, HTML, RTF, TXT, EPUB135136## Command-Line Reference137138```bash139soffice --headless140soffice --headless --convert-to <format> <file>141soffice --writer # Writer142soffice --calc # Calc143soffice --impress # Impress144soffice --draw # Draw145```146147## Python Libraries148149```bash150pip install odfpy # ODF manipulation151pip install ezodf # Easier ODF handling152```153154## Best Practices1551561. Use styles for consistency1572. Create templates for recurring documents1583. Ensure accessibility (heading hierarchy, alt text)1594. Fill document metadata1605. Store ODT source files in version control1616. Test conversions thoroughly1627. Embed fonts for PDF distribution1638. Handle conversion failures gracefully1649. Log automation operations16510. Clean temporary files166167## Troubleshooting168169### Cannot open socket170```bash171killall soffice.bin172soffice --headless --accept="socket,host=localhost,port=8100;urp;"173```174175### Conversion Quality Issues176```bash177soffice --headless --convert-to pdf:writer_pdf_Export document.odt178```179180## Resources181182- [LibreOffice Writer Guide](https://documentation.libreoffice.org/)183- [LibreOffice SDK](https://wiki.documentfoundation.org/Documentation/DevGuide)184- [UNO API Reference](https://api.libreoffice.org/)185- [odfpy](https://pypi.org/project/odfpy/)186187## Related Skills188189- calc190- impress191- draw192- base193- docx-official194- pdf-official195- workflow-automation196197## Limitations198- Use this skill only when the task clearly matches the scope described above.199- Do not treat the output as a substitute for enprojectnment-specific validation, testing, or expert review.200- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.