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
1---2name: writer3description: Document creation, format conversion (ODT/DOCX/PDF), mail merge, and automation with LibreOffice Writer.4license: MIT5---6# LibreOffice Writer
7
8## Overview
9
10LibreOffice Writer skill for creating, editing, converting, and automating document workflows using the native ODT (OpenDocument Text) format.
11
12## When to Use This Skill
13
14Use this skill when:
15- Creating new documents in ODT format
16- Converting documents between formats (ODT <-> DOCX, PDF, HTML, RTF, TXT)
17- Automating document generation workflows
18- Performing batch document operations
19- Creating templates and standardized document formats
20
21## Core Capabilities
22
23### 1. Document Creation
24- Create new ODT documents from scratch
25- Generate documents from templates
26- Create mail merge documents
27- Build forms with fillable fields
28
29### 2. Format Conversion
30- ODT to other formats: DOCX, PDF, HTML, RTF, TXT, EPUB
31- Other formats to ODT: DOCX, DOC, RTF, HTML, TXT
32- Batch conversion of multiple documents
33
34### 3. Document Automation
35- Template-based document generation
36- Mail merge with data sources (CSV, spreadsheet, database)
37- Batch document processing
38- Automated report generation
39
40### 4. Content Manipulation
41- Text extraction and insertion
42- Style management and application
43- Table creation and manipulation
44- Header/footer management
45
46### 5. Integration
47- Command-line automation via soffice
48- Python scripting with UNO
49- Integration with workflow automation tools
50
51## Workflows
52
53### Creating a New Document
54
55#### Method 1: Command-Line
56```bash
57soffice --writer template.odt
58```
59
60#### Method 2: Python with UNO
61```python
62import uno
63
64def create_document():
65 local_ctx = uno.getComponentContext()
66 resolver = local_ctx.ServiceManager.createInstanceWithContext(
67 "com.sun.star.bridge.UnoUrlResolver", local_ctx
68 )
69 ctx = resolver.resolve(
70 "uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext"
71 )
72 smgr = ctx.ServiceManager
73 doc = smgr.createInstanceWithContext("com.sun.star.text.TextDocument", ctx)
74 text = doc.Text
75 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```
80
81#### Method 3: Using odfpy
82```python
83from odf.opendocument import OpenDocumentText
84from odf.text import P, H
85
86doc = OpenDocumentText()
87h1 = H(outlinelevel='1', text='Document Title')
88doc.text.appendChild(h1)
89doc.save("document.odt")
90```
91
92### Converting Documents
93
94```bash
95# ODT to DOCX
96soffice --headless --convert-to docx document.odt
97
98# ODT to PDF
99soffice --headless --convert-to pdf document.odt
100
101# DOCX to ODT
102soffice --headless --convert-to odt document.docx
103
104# Batch convert
105for file in *.odt; do
106 soffice --headless --convert-to pdf "$file"
107done
108```
109
110### Template-Based Generation
111```python
112import subprocess
113import tempfile
114from pathlib import Path
115
116def 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_path
126```
127
128## Format Conversion Reference
129
130### Supported Input Formats
131- ODT (native), DOCX, DOC, RTF, HTML, TXT, EPUB
132
133### Supported Output Formats
134- ODT, DOCX, PDF, PDF/A, HTML, RTF, TXT, EPUB
135
136## Command-Line Reference
137
138```bash
139soffice --headless
140soffice --headless --convert-to <format> <file>
141soffice --writer # Writer
142soffice --calc # Calc
143soffice --impress # Impress
144soffice --draw # Draw
145```
146
147## Python Libraries
148
149```bash
150pip install odfpy # ODF manipulation
151pip install ezodf # Easier ODF handling
152```
153
154## Best Practices
155
1561. Use styles for consistency
1572. Create templates for recurring documents
1583. Ensure accessibility (heading hierarchy, alt text)
1594. Fill document metadata
1605. Store ODT source files in version control
1616. Test conversions thoroughly
1627. Embed fonts for PDF distribution
1638. Handle conversion failures gracefully
1649. Log automation operations
16510. Clean temporary files
166
167## Troubleshooting
168
169### Cannot open socket
170```bash
171killall soffice.bin
172soffice --headless --accept="socket,host=localhost,port=8100;urp;"
173```
174
175### Conversion Quality Issues
176```bash
177soffice --headless --convert-to pdf:writer_pdf_Export document.odt
178```
179
180## Resources
181
182- [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/)
186
187## Related Skills
188
189- calc
190- impress
191- draw
192- base
193- docx-official
194- pdf-official
195- workflow-automation