Bulk Convert Documents Using LibreOffice CLI

Converting document formats in bulk is a common requirement for automated workflows, digital archiving, and administrative management. LibreOffice offers a headless command-line interface (CLI) that enables batch conversions of various document formats—including DOCX, XLSX, PPTX, ODT, and HTML—into formats such as PDF, TXT, or EPUB without opening a graphical user interface. This guide details the essential command syntax, explains how to execute bulk conversions across different operating systems, and provides practical automation scripts.

The Basic LibreOffice Conversion Command

The core command relies on the LibreOffice binary (soffice or libreoffice) combined with the --headless and --convert-to flags.

The standard syntax is:

soffice --headless --convert-to <target_format> <input_file> --outdir <output_directory>

Bulk Conversion on Linux and macOS

1. Converting Files in the Same Directory

To convert all files of a specific type in your current directory, use standard shell wildcards:

libreoffice --headless --convert-to pdf *.docx --outdir ./converted_pdfs

This command processes every .docx file in the folder and saves the resulting PDFs in the converted_pdfs directory.

2. Recursive Batch Conversion

To convert files across nested subdirectories, use the find command:

find /path/to/source -type f -name "*.docx" -exec libreoffice --headless --convert-to pdf {} --outdir /path/to/destination \;

This searches /path/to/source recursively for all .docx files and runs the conversion command on each file found.

Bulk Conversion on Windows

On Windows, the executable is typically located at C:\Program Files\LibreOffice\program\soffice.exe.

1. Using Command Prompt

To process multiple files in a folder using the standard Command Prompt:

for %f in (*.docx) do "C:\Program Files\LibreOffice\program\soffice.exe" --headless --convert-to pdf "%f" --outdir "C:\ConvertedFiles"

Note: If writing this command inside a .bat batch file, use %%f instead of %f.

2. Using PowerShell

PowerShell allows for clean scripting and robust pipeline processing:

Get-ChildItem -Path "C:\SourceFiles" -Filter *.docx | ForEach-Object {
    & "C:\Program Files\LibreOffice\program\soffice.exe" --headless --convert-to pdf $_.FullName --outdir "C:\ConvertedFiles"
}

To search subdirectories recursively in PowerShell, add the -Recurse flag to Get-ChildItem:

Get-ChildItem -Path "C:\SourceFiles" -Filter *.docx -Recurse | ForEach-Object {
    & "C:\Program Files\LibreOffice\program\soffice.exe" --headless --convert-to pdf $_.FullName --outdir "C:\ConvertedFiles"
}

Specifying Conversion Filters

LibreOffice automatically selects an appropriate filter for common extensions, but specific filters can be enforced when necessary. Filter names follow the format:

--convert-to <extension>:"<filter_name>"

Examples of Filtered Conversions

Common Supported Formats

LibreOffice CLI supports conversions between a wide array of formats:

Category Input Formats Common Output Formats
Word Processing DOCX, DOC, ODT, RTF, TXT, HTML PDF, DOCX, ODT, TXT, EPUB
Spreadsheets XLSX, XLS, ODS, CSV PDF, CSV, XLSX, ODS, HTML
Presentations PPTX, PPT, ODP PDF, PPTX, ODP, SWF
Drawings/Vector VSD, VSDX, ODG, SVG PDF, PNG, SVG