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."4source: personal5risk: safe6domain: office-productivity7category: document-processing8version: 1.0.09---1011# LibreOffice Writer1213## Overview1415LibreOffice Writer skill for creating, editing, converting, and automating document workflows using the native ODT (OpenDocument Text) format.1617## When to Use This Skill1819Use this skill when:20- Creating new documents in ODT format21- Converting documents between formats (ODT <-> DOCX, PDF, HTML, RTF, TXT)22- Automating document generation workflows23- Performing batch document operations24- Creating templates and standardized document formats2526## Core Capabilities2728### 1. Document Creation29- Create new ODT documents from scratch30- Generate documents from templates31- Create mail merge documents32- Build forms with fillable fields3334### 2. Format Conversion35- ODT to other formats: DOCX, PDF, HTML, RTF, TXT, EPUB36- Other formats to ODT: DOCX, DOC, RTF, HTML, TXT37- Batch conversion of multiple documents3839### 3. Document Automation40- Template-based document generation41- Mail merge with data sources (CSV, spreadsheet, database)42- Batch document processing43- Automated report generation4445### 4. Content Manipulation46- Text extraction and insertion47- Style management and application48- Table creation and manipulation49- Header/footer management5051### 5. Integration52- Command-line automation via soffice53- Python scripting with UNO54- Integration with workflow automation tools5556## Workflows5758### Creating a New Document5960#### Method 1: Command-Line61```bash62soffice --writer template.odt63```6465#### Method 2: Python with UNO66```python67import uno6869def create_document():70 local_ctx = uno.getComponentContext()71 resolver = local_ctx.ServiceManager.createInstanceWithContext(72 "com.sun.star.bridge.UnoUrlResolver", local_ctx73 )74 ctx = resolver.resolve(75 "uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext"76 )77 smgr = ctx.ServiceManager78 doc = smgr.createInstanceWithContext("com.sun.star.text.TextDocument", ctx)79 text = doc.Text80 cursor = text.createTextCursor()81 text.insertString(cursor, "Hello from LibreOffice Writer!", 0)82 doc.storeToURL("file:///path/to/document.odt", ())83 doc.close(True)84```8586#### Method 3: Using odfpy87```python88from odf.opendocument import OpenDocumentText89from odf.text import P, H9091doc = OpenDocumentText()92h1 = H(outlinelevel='1', text='Document Title')93doc.text.appendChild(h1)94doc.save("document.odt")95```9697### Converting Documents9899```bash100# ODT to DOCX101soffice --headless --convert-to docx document.odt102103# ODT to PDF104soffice --headless --convert-to pdf document.odt105106# DOCX to ODT107soffice --headless --convert-to odt document.docx108109# Batch convert110for file in *.odt; do111 soffice --headless --convert-to pdf "$file"112done113```114115### Template-Based Generation116```python117import subprocess118import tempfile119from pathlib import Path120121def generate_from_template(template_path, variables, output_path):122 with tempfile.TemporaryDirectory() as tmpdir:123 subprocess.run(['unzip', '-q', template_path, '-d', tmpdir])124 content_file = Path(tmpdir) / 'content.xml'125 content = content_file.read_text()126 for key, value in variables.items():127 content = content.replace(f'${{{key}}}', str(value))128 content_file.write_text(content)129 subprocess.run(['zip', '-rq', output_path, '.'], cwd=tmpdir)130 return output_path131```132133## Format Conversion Reference134135### Supported Input Formats136- ODT (native), DOCX, DOC, RTF, HTML, TXT, EPUB137138### Supported Output Formats139- ODT, DOCX, PDF, PDF/A, HTML, RTF, TXT, EPUB140141## Command-Line Reference142143```bash144soffice --headless145soffice --headless --convert-to <format> <file>146soffice --writer # Writer147soffice --calc # Calc148soffice --impress # Impress149soffice --draw # Draw150```151152## Python Libraries153154```bash155pip install odfpy # ODF manipulation156pip install ezodf # Easier ODF handling157```158159## Best Practices1601611. Use styles for consistency1622. Create templates for recurring documents1633. Ensure accessibility (heading hierarchy, alt text)1644. Fill document metadata1655. Store ODT source files in version control1666. Test conversions thoroughly1677. Embed fonts for PDF distribution1688. Handle conversion failures gracefully1699. Log automation operations17010. Clean temporary files171172## Troubleshooting173174### Cannot open socket175```bash176killall soffice.bin177soffice --headless --accept="socket,host=localhost,port=8100;urp;"178```179180### Conversion Quality Issues181```bash182soffice --headless --convert-to pdf:writer_pdf_Export document.odt183```184185## Resources186187- [LibreOffice Writer Guide](https://documentation.libreoffice.org/)188- [LibreOffice SDK](https://wiki.documentfoundation.org/Documentation/DevGuide)189- [UNO API Reference](https://api.libreoffice.org/)190- [odfpy](https://pypi.org/project/odfpy/)191192## Related Skills193194- calc195- impress196- draw197- base198- docx-official199- pdf-official200- workflow-automation