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 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: libreoffice-writer3description: Document creation, format conversion (ODT/DOCX/PDF), mail merge, and automation with LibreOffice Writer.4---5# LibreOffice Writer67## Overview89LibreOffice Writer skill for creating, editing, converting, and automating document workflows using the native ODT (OpenDocument Text) format.1011## When to Use This Skill1213Use this skill when:14- Creating new documents in ODT format15- Converting documents between formats (ODT <-> DOCX, PDF, HTML, RTF, TXT)16- Automating document generation workflows17- Performing batch document operations18- Creating templates and standardized document formats1920## Core Capabilities2122### 1. Document Creation23- Create new ODT documents from scratch24- Generate documents from templates25- Create mail merge documents26- Build forms with fillable fields2728### 2. Format Conversion29- ODT to other formats: DOCX, PDF, HTML, RTF, TXT, EPUB30- Other formats to ODT: DOCX, DOC, RTF, HTML, TXT31- Batch conversion of multiple documents3233### 3. Document Automation34- Template-based document generation35- Mail merge with data sources (CSV, spreadsheet, database)36- Batch document processing37- Automated report generation3839### 4. Content Manipulation40- Text extraction and insertion41- Style management and application42- Table creation and manipulation43- Header/footer management4445### 5. Integration46- Command-line automation via soffice47- Python scripting with UNO48- Integration with workflow automation tools4950## Workflows5152### Creating a New Document5354#### Method 1: Command-Line55```bash56soffice --writer template.odt57```5859#### Method 2: Python with UNO60```python61import uno6263def create_document():64 local_ctx = uno.getComponentContext()65 resolver = local_ctx.ServiceManager.createInstanceWithContext(66 "com.sun.star.bridge.UnoUrlResolver", local_ctx67 )68 ctx = resolver.resolve(69 "uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext"70 )71 smgr = ctx.ServiceManager72 doc = smgr.createInstanceWithContext("com.sun.star.text.TextDocument", ctx)73 text = doc.Text74 cursor = text.createTextCursor()75 text.insertString(cursor, "Hello from LibreOffice Writer!", 0)76 doc.storeToURL("file:///path/to/document.odt", ())77 doc.close(True)78```7980#### Method 3: Using odfpy81```python82from odf.opendocument import OpenDocumentText83from odf.text import P, H8485doc = OpenDocumentText()86h1 = H(outlinelevel='1', text='Document Title')87doc.text.appendChild(h1)88doc.save("document.odt")89```9091### Converting Documents9293```bash94# ODT to DOCX95soffice --headless --convert-to docx document.odt9697# ODT to PDF98soffice --headless --convert-to pdf document.odt99100# DOCX to ODT101soffice --headless --convert-to odt document.docx102103# Batch convert104for file in *.odt; do105 soffice --headless --convert-to pdf "$file"106done107```108109### Template-Based Generation110```python111import subprocess112import tempfile113from pathlib import Path114115def generate_from_template(template_path, variables, output_path):116 with tempfile.TemporaryDirectory() as tmpdir:117 subprocess.run(['unzip', '-q', template_path, '-d', tmpdir])118 content_file = Path(tmpdir) / 'content.xml'119 content = content_file.read_text()120 for key, value in variables.items():121 content = content.replace(f'${{{key}}}', str(value))122 content_file.write_text(content)123 subprocess.run(['zip', '-rq', output_path, '.'], cwd=tmpdir)124 return output_path125```126127## Format Conversion Reference128129### Supported Input Formats130- ODT (native), DOCX, DOC, RTF, HTML, TXT, EPUB131132### Supported Output Formats133- ODT, DOCX, PDF, PDF/A, HTML, RTF, TXT, EPUB134135## Command-Line Reference136137```bash138soffice --headless139soffice --headless --convert-to <format> <file>140soffice --writer # Writer141soffice --calc # Calc142soffice --impress # Impress143soffice --draw # Draw144```145146## Python Libraries147148```bash149pip install odfpy # ODF manipulation150pip install ezodf # Easier ODF handling151```152153## Best Practices1541551. Use styles for consistency1562. Create templates for recurring documents1573. Ensure accessibility (heading hierarchy, alt text)1584. Fill document metadata1595. Store ODT source files in version control1606. Test conversions thoroughly1617. Embed fonts for PDF distribution1628. Handle conversion failures gracefully1639. Log automation operations16410. Clean temporary files165166## Troubleshooting167168### Cannot open socket169```bash170killall soffice.bin171soffice --headless --accept="socket,host=localhost,port=8100;urp;"172```173174### Conversion Quality Issues175```bash176soffice --headless --convert-to pdf:writer_pdf_Export document.odt177```178179## Resources180181- [LibreOffice Writer Guide](https://documentation.libreoffice.org/)182- [LibreOffice SDK](https://wiki.documentfoundation.org/Documentation/DevGuide)183- [UNO API Reference](https://api.libreoffice.org/)184- [odfpy](https://pypi.org/project/odfpy/)185186## Related Skills187188- calc189- impress190- draw191- base192- docx-official193- pdf-official194- workflow-automation195196## Limitations197- Use this skill only when the task clearly matches the scope described above.198- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.199- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.