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.09metadata:10 source: https://skillmd.com/skills/mayurrathi/writer11---1213# LibreOffice Writer1415## Overview1617LibreOffice Writer skill for creating, editing, converting, and automating document workflows using the native ODT (OpenDocument Text) format.1819## When to Use This Skill2021Use this skill when:22- Creating new documents in ODT format23- Converting documents between formats (ODT <-> DOCX, PDF, HTML, RTF, TXT)24- Automating document generation workflows25- Performing batch document operations26- Creating templates and standardized document formats2728## Core Capabilities2930### 1. Document Creation31- Create new ODT documents from scratch32- Generate documents from templates33- Create mail merge documents34- Build forms with fillable fields3536### 2. Format Conversion37- ODT to other formats: DOCX, PDF, HTML, RTF, TXT, EPUB38- Other formats to ODT: DOCX, DOC, RTF, HTML, TXT39- Batch conversion of multiple documents4041### 3. Document Automation42- Template-based document generation43- Mail merge with data sources (CSV, spreadsheet, database)44- Batch document processing45- Automated report generation4647### 4. Content Manipulation48- Text extraction and insertion49- Style management and application50- Table creation and manipulation51- Header/footer management5253### 5. Integration54- Command-line automation via soffice55- Python scripting with UNO56- Integration with workflow automation tools5758## Workflows5960### Creating a New Document6162#### Method 1: Command-Line63```bash64soffice --writer template.odt65```6667#### Method 2: Python with UNO68```python69import uno7071def create_document():72 local_ctx = uno.getComponentContext()73 resolver = local_ctx.ServiceManager.createInstanceWithContext(74 "com.sun.star.bridge.UnoUrlResolver", local_ctx75 )76 ctx = resolver.resolve(77 "uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext"78 )79 smgr = ctx.ServiceManager80 doc = smgr.createInstanceWithContext("com.sun.star.text.TextDocument", ctx)81 text = doc.Text82 cursor = text.createTextCursor()83 text.insertString(cursor, "Hello from LibreOffice Writer!", 0)84 doc.storeToURL("file:///path/to/document.odt", ())85 doc.close(True)86```8788#### Method 3: Using odfpy89```python90from odf.opendocument import OpenDocumentText91from odf.text import P, H9293doc = OpenDocumentText()94h1 = H(outlinelevel='1', text='Document Title')95doc.text.appendChild(h1)96doc.save("document.odt")97```9899### Converting Documents100101```bash102# ODT to DOCX103soffice --headless --convert-to docx document.odt104105# ODT to PDF106soffice --headless --convert-to pdf document.odt107108# DOCX to ODT109soffice --headless --convert-to odt document.docx110111# Batch convert112for file in *.odt; do113 soffice --headless --convert-to pdf "$file"114done115```116117### Template-Based Generation118```python119import subprocess120import tempfile121from pathlib import Path122123def generate_from_template(template_path, variables, output_path):124 with tempfile.TemporaryDirectory() as tmpdir:125 subprocess.run(['unzip', '-q', template_path, '-d', tmpdir])126 content_file = Path(tmpdir) / 'content.xml'127 content = content_file.read_text()128 for key, value in variables.items():129 content = content.replace(f'${{{key}}}', str(value))130 content_file.write_text(content)131 subprocess.run(['zip', '-rq', output_path, '.'], cwd=tmpdir)132 return output_path133```134135## Format Conversion Reference136137### Supported Input Formats138- ODT (native), DOCX, DOC, RTF, HTML, TXT, EPUB139140### Supported Output Formats141- ODT, DOCX, PDF, PDF/A, HTML, RTF, TXT, EPUB142143## Command-Line Reference144145```bash146soffice --headless147soffice --headless --convert-to <format> <file>148soffice --writer # Writer149soffice --calc # Calc150soffice --impress # Impress151soffice --draw # Draw152```153154## Python Libraries155156```bash157pip install odfpy # ODF manipulation158pip install ezodf # Easier ODF handling159```160161## Best Practices1621631. Use styles for consistency1642. Create templates for recurring documents1653. Ensure accessibility (heading hierarchy, alt text)1664. Fill document metadata1675. Store ODT source files in version control1686. Test conversions thoroughly1697. Embed fonts for PDF distribution1708. Handle conversion failures gracefully1719. Log automation operations17210. Clean temporary files173174## Troubleshooting175176### Cannot open socket177```bash178killall soffice.bin179soffice --headless --accept="socket,host=localhost,port=8100;urp;"180```181182### Conversion Quality Issues183```bash184soffice --headless --convert-to pdf:writer_pdf_Export document.odt185```186187## Resources188189- [LibreOffice Writer Guide](https://documentation.libreoffice.org/)190- [LibreOffice SDK](https://wiki.documentfoundation.org/Documentation/DevGuide)191- [UNO API Reference](https://api.libreoffice.org/)192- [odfpy](https://pypi.org/project/odfpy/)193194## Related Skills195196- calc197- impress198- draw199- base200- docx-official201- pdf-official202- workflow-automation