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: writer
3description: Document creation, format conversion (ODT/DOCX/PDF), mail merge, and
4 automation with LibreOffice Writer.
5category: document-processing
6risk: safe
7source: personal
8date_added: '2026-02-27'
9license: MIT
10metadata:
11 source: https://skillmd.com/skills/jantoniofc/writer
12---
13
14# LibreOffice Writer
15
16## Overview
17
18LibreOffice Writer skill for creating, editing, converting, and automating document workflows using the native ODT (OpenDocument Text) format.
19
20## When to Use This Skill
21
22Use this skill when:
23- Creating new documents in ODT format
24- Converting documents between formats (ODT <-> DOCX, PDF, HTML, RTF, TXT)
25- Automating document generation workflows
26- Performing batch document operations
27- Creating templates and standardized document formats
28
29## Core Capabilities
30
31### 1. Document Creation
32- Create new ODT documents from scratch
33- Generate documents from templates
34- Create mail merge documents
35- Build forms with fillable fields
36
37### 2. Format Conversion
38- ODT to other formats: DOCX, PDF, HTML, RTF, TXT, EPUB
39- Other formats to ODT: DOCX, DOC, RTF, HTML, TXT
40- Batch conversion of multiple documents
41
42### 3. Document Automation
43- Template-based document generation
44- Mail merge with data sources (CSV, spreadsheet, database)
45- Batch document processing
46- Automated report generation
47
48### 4. Content Manipulation
49- Text extraction and insertion
50- Style management and application
51- Table creation and manipulation
52- Header/footer management
53
54### 5. Integration
55- Command-line automation via soffice
56- Python scripting with UNO
57- Integration with workflow automation tools
58
59## Workflows
60
61### Creating a New Document
62
63#### Method 1: Command-Line
64```bash
65soffice --writer template.odt
66```
67
68#### Method 2: Python with UNO
69```python
70import uno
71
72def create_document():
73 local_ctx = uno.getComponentContext()
74 resolver = local_ctx.ServiceManager.createInstanceWithContext(
75 "com.sun.star.bridge.UnoUrlResolver", local_ctx
76 )
77 ctx = resolver.resolve(
78 "uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext"
79 )
80 smgr = ctx.ServiceManager
81 doc = smgr.createInstanceWithContext("com.sun.star.text.TextDocument", ctx)
82 text = doc.Text
83 cursor = text.createTextCursor()
84 text.insertString(cursor, "Hello from LibreOffice Writer!", 0)
85 doc.storeToURL("file:///path/to/document.odt", ())
86 doc.close(True)
87```
88
89#### Method 3: Using odfpy
90```python
91from odf.opendocument import OpenDocumentText
92from odf.text import P, H
93
94doc = OpenDocumentText()
95h1 = H(outlinelevel='1', text='Document Title')
96doc.text.appendChild(h1)
97doc.save("document.odt")
98```
99
100### Converting Documents
101
102```bash
103# ODT to DOCX
104soffice --headless --convert-to docx document.odt
105
106# ODT to PDF
107soffice --headless --convert-to pdf document.odt
108
109# DOCX to ODT
110soffice --headless --convert-to odt document.docx
111
112# Batch convert
113for file in *.odt; do
114 soffice --headless --convert-to pdf "$file"
115done
116```
117
118### Template-Based Generation
119```python
120import subprocess
121import tempfile
122from pathlib import Path
123
124def generate_from_template(template_path, variables, output_path):
125 with tempfile.TemporaryDirectory() as tmpdir:
126 subprocess.run(['unzip', '-q', template_path, '-d', tmpdir])
127 content_file = Path(tmpdir) / 'content.xml'
128 content = content_file.read_text()
129 for key, value in variables.items():
130 content = content.replace(f'${{{key}}}', str(value))
131 content_file.write_text(content)
132 subprocess.run(['zip', '-rq', output_path, '.'], cwd=tmpdir)
133 return output_path
134```
135
136## Format Conversion Reference
137
138### Supported Input Formats
139- ODT (native), DOCX, DOC, RTF, HTML, TXT, EPUB
140
141### Supported Output Formats
142- ODT, DOCX, PDF, PDF/A, HTML, RTF, TXT, EPUB
143
144## Command-Line Reference
145
146```bash
147soffice --headless
148soffice --headless --convert-to <format> <file>
149soffice --writer # Writer
150soffice --calc # Calc
151soffice --impress # Impress
152soffice --draw # Draw
153```
154
155## Python Libraries
156
157```bash
158pip install odfpy # ODF manipulation
159pip install ezodf # Easier ODF handling
160```
161
162## Best Practices
163
1641. Use styles for consistency
1652. Create templates for recurring documents
1663. Ensure accessibility (heading hierarchy, alt text)
1674. Fill document metadata
1685. Store ODT source files in version control
1696. Test conversions thoroughly
1707. Embed fonts for PDF distribution
1718. Handle conversion failures gracefully
1729. Log automation operations
17310. Clean temporary files
174
175## Troubleshooting
176
177### Cannot open socket
178```bash
179killall soffice.bin
180soffice --headless --accept="socket,host=localhost,port=8100;urp;"
181```
182
183### Conversion Quality Issues
184```bash
185soffice --headless --convert-to pdf:writer_pdf_Export document.odt
186```
187
188## Resources
189
190- [LibreOffice Writer Guide](https://documentation.libreoffice.org/)
191- [LibreOffice SDK](https://wiki.documentfoundation.org/Documentation/DevGuide)
192- [UNO API Reference](https://api.libreoffice.org/)
193- [odfpy](https://pypi.org/project/odfpy/)
194
195## Related Skills
196
197- calc
198- impress
199- draw
200- base
201- docx-official
202- pdf-official
203- workflow-automation