Print LibreOffice Documents via Command Line to a Printer
This guide explains how to print LibreOffice documents silently to a specific printer using command-line arguments. By running LibreOffice in headless mode with targeted print parameters, you can automate batch printing jobs and integrate document printing into scripts without launching the graphical user interface.
The Core Command
To print a document silently to a specific printer, use the following syntax:
soffice --headless --pt "Printer_Name" "path/to/document.odt"(Note: Depending on your operating system and installation, you
can use either soffice or libreoffice as the
executable command.)
Command-Line Arguments Explained
--headless: Starts LibreOffice in headless mode, which prevents the graphical user interface (GUI) from loading. This ensures the command runs entirely in the background.--pt <Printer_Name>: Directs the output to the specified printer name. The argument requires the exact name of the target printer. If the printer name contains spaces, enclose it in quotation marks.--invisible(Optional): Prevents the initial splash screen and window creation. When combined with--headless, it ensures no desktop notifications or windows appear.
Finding the Exact Printer Name
To ensure the command executes correctly, you must provide the exact printer name recognized by your operating system.
Linux and macOS
List all available printer names using the CUPS command:
lpstat -p -dWindows
List all available printers using PowerShell:
Get-Printer | Select-Object NamePractical Examples
Linux / macOS Example
Print a Word document (report.docx) to an office network
printer named Office_HP_LaserJet:
libreoffice --headless --pt "Office_HP_LaserJet" /home/user/documents/report.docxWindows Example
Print a spreadsheet (budget.xlsx) to a local printer
named Canon_TS8300:
"C:\Program Files\LibreOffice\program\soffice.exe" --headless --pt "Canon_TS8300" "C:\Users\Username\Documents\budget.xlsx"Printing to the Default Printer
If you want to print silently to the system’s default printer rather
than specifying one, use the -p or
--print-to-default argument instead:
soffice --headless -p "path/to/document.odt"