LibreOffice as a Headless Conversion Tool
LibreOffice's --headless mode converts documents from the command line without a GUI — making it the most powerful free batch document conversion tool available.
Converts: DOCX/DOC → PDF, ODT, HTML, TXT | XLSX/XLS → PDF, ODS, CSV | PPTX/PPT → PDF, ODP | RTF → DOCX, PDF.
Installation
sudo apt install libreoffice # Ubuntu/Debian
brew install --cask libreoffice # macOS
choco install libreoffice # Windows
Basic Conversion
libreoffice --headless --convert-to pdf document.docx
libreoffice --headless --convert-to pdf spreadsheet.xlsx
libreoffice --headless --convert-to pdf presentation.pptx
libreoffice --headless --convert-to odt document.docx
libreoffice --headless --convert-to csv spreadsheet.xlsx
Specify Output Directory
libreoffice --headless --convert-to pdf --outdir /path/output/ document.docx
libreoffice --headless --convert-to pdf --outdir /pdfs/ *.docx
Batch Conversion
find /documents/ -name "*.docx" -exec \
libreoffice --headless --convert-to pdf --outdir /output/ {} \;
# Parallel processing (faster)
find /documents/ -name "*.docx" | \
parallel -j4 libreoffice --headless --convert-to pdf --outdir /output/ {}
Using with Python
import subprocess, os
from pathlib import Path
def docx_to_pdf(input_path, output_dir):
os.makedirs(output_dir, exist_ok=True)
result = subprocess.run([
'libreoffice', '--headless', '--convert-to', 'pdf',
'--outdir', output_dir, input_path
], capture_output=True, timeout=120)
return result.returncode == 0
for f in Path('/documents').glob('*.docx'):
ok = docx_to_pdf(str(f), '/pdfs')
print(f"{'✓' if ok else '✗'} {f.name}")
Common Issues
"user profile locked" — multiple parallel instances:
libreoffice --env:UserInstallation="file:///tmp/lo-$RANDOM" \
--headless --convert-to pdf document.docx
Missing fonts on Linux:
sudo apt install fonts-liberation fonts-dejavu fonts-freefont-ttf
VBA macros don't execute in headless mode for security.
Conclusion
LibreOffice headless is the most powerful free tool for batch document-to-PDF conversion. Combined with parallel or Python subprocess, it scales to thousands of documents per hour.
Advanced Use Cases
Legal and business workflow: signed contracts are distributed in PDF/A (PDF Archival) which guarantees the document renders identically in 50 years — all fonts embedded, no JavaScript, no dynamic content. Electronic signature (PAdES, advanced eSignatures) is integrated in PDF and validates cryptographically. Academic publishing: theses and papers use LaTeX → PDF for precise mathematical formulas; journals require specific format (Word with styles, LaTeX with journal class, or both). Converting between LaTeX, DOCX and PDF preserving semantic structure (citations, references, equations) requires specialized tools like Pandoc. E-books: Amazon KDP requires MOBI (legacy) or KFX (modern) format generated from EPUB; Apple Books accepts EPUB natively; Kobo, PocketBook and Nook prefer EPUB; Google Play Books accepts PDF and EPUB. Converting DOCX manuscript to EPUB requires attention to semantic markup (hierarchical headings, lists, blockquotes) so reflowable layout works well. Translation workflows: professional translators prefer XLIFF as intermediate format — maintains segmentation, translation memory matches, and context info that is lost in plain text export.
Best Practices and Professional Tips
Style preservation: when converting between editable formats (DOCX↔ODT↔RTF), always use defined styles instead of direct formatting — Heading 1/2/3 vs "16pt Bold". This guarantees outline preservation and conversion maintains hierarchical structure. Font embedding: for cross-platform distribution (PDF), embed all non-standard fonts — without embedding, readers automatically substitute with available fonts which can break layout. PDF/A for archival: for legal, regulatory or permanent archive documents, export as PDF/A-1b (basic) or PDF/A-2u (Unicode + JPEG2000) — doesn't allow dynamic content, guarantees self-contained rendering. Revision history: PDF, DOCX and ODT support tracked changes and comments — when converting, decide if you want to preserve them (DOCX→DOCX or DOCX→ODT) or flatten them (DOCX→PDF typically accepts only the final state). Accessibility: PDF documents for public distribution should comply with PDF/UA — heading structure, alt text on images, defined reading order for screen readers.
Compatibility and Technical Considerations
KaijuConverter uses LibreOffice 7.6 headless as the main engine with Pandoc 3.x as fallback for complex markup conversions. We support more than 60 document formats (PDF, DOCX, DOC, ODT, RTF, TXT, HTML, MD, EPUB, MOBI, AZW3, FB2, LaTeX, RST and more). Format fidelity: we preserve fonts (with substitution fallback if original font is not on system), sizes, colors, complete paragraphs with indentation and line spacing, nested lists, tables with cell merging and complex borders, embedded images with anchor positioning, headers/footers with dynamic fields (page number, date, document title), footnotes and endnotes. PDF conversion: we guarantee PDF/A-conforming output when required, with correct font embedding and ICC profile embedding for absolute color fidelity. Limitations: documents with macros (DOCX with VBA) don't execute macros during conversion — only static content is preserved. Scanned PDFs (image without OCR) are not editable — they need previous OCR (Tesseract, ABBYY) to extract text. Privacy: TLS 1.3, isolated Docker containers, deletion after 2 hours. Performance: typical 20-page document takes 3-8 seconds; large documents with many images may require 15-30 seconds.
Related conversions
Document conversions that follow this topic naturally: