How to Run LibreOffice Headless via Command Line
Running LibreOffice in headless mode allows you to execute office suite operations—such as converting documents, batch processing files, and printing—directly from the terminal or automated scripts without launching the graphical user interface (GUI). This guide explains the core command syntax, essential flags, and practical examples for running LibreOffice headless across different operating systems.
Basic Syntax and Key Flags
The general syntax for executing LibreOffice commands in headless mode is:
libreoffice --headless [options] [file](Note: Depending on your operating system or installation, the
binary name may be soffice instead of
libreoffice.)
Key flags include: * --headless: Runs LibreOffice
without opening the graphical interface or user windows. *
--convert-to <output_extension>: Converts the input
document into the specified file format. *
--outdir <directory_path>: Defines the target folder
where the converted output will be saved. *
--print-to-file: Prints the file to an output format
without UI interaction.
Common Use Cases
1. Converting a Document to PDF
To convert a single document (such as a .docx,
.odt, or .xlsx file) directly into a PDF:
libreoffice --headless --convert-to pdf document.docx2. Specifying an Output Directory
By default, converted files are placed in the current working
directory. Use --outdir to specify a different
destination:
libreoffice --headless --convert-to pdf document.docx --outdir /path/to/output/3. Batch Converting Files
You can convert multiple files at once using shell wildcards:
libreoffice --headless --convert-to pdf *.docx --outdir /path/to/output/4. Converting Between Other Formats
Headless mode supports conversions between various supported formats, such as HTML, plain text, or image formats:
DOCX to Plain Text:
libreoffice --headless --convert-to txt:Text document.docxSpreadsheet to CSV:
libreoffice --headless --convert-to csv spreadsheet.xlsxDocument to HTML:
libreoffice --headless --convert-to html document.odt
Operating System Path Details
If the libreoffice or soffice command is
not recognized in your system’s PATH, use the full binary path:
Linux: Typically located at
/usr/bin/libreofficeor/usr/bin/soffice.macOS: Located inside the application bundle:
/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf document.docxWindows: Located in the LibreOffice installation directory (use Command Prompt or PowerShell):
"C:\Program Files\LibreOffice\program\soffice.exe" --headless --convert-to pdf document.docx