zahfouf / php-libreoffice
Framework-agnostic LibreOffice headless document conversion library for PHP.
v1.2.3
2026-02-22 01:23 UTC
Requires
- php: ^8.1
- symfony/console: ^6.1 || ^7.0
- symfony/process: ^6.1 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^10.5
- symfony/var-exporter: ^6.1 || ^7.0
README
Simple PHP package to convert Word files (.doc, .docx) to PDF using LibreOffice (soffice) in headless mode.
Installation
composer require zahfouf/php-libreoffice
CLI Commands
After installation, the CLI binary is available at:
vendor/bin/libreoffice
lo:install
Installs LibreOffice automatically on Ubuntu/Debian.
vendor/bin/libreoffice lo:install
Notes:
- Windows: automatic installation is not supported (the command prints the official download URL).
- Non-Debian/Ubuntu Linux: install LibreOffice using your distribution package manager.
lo:probe
Checks that the LibreOffice binary works and saves default values:
- binary path (
binary) - temporary directory (
temp_dir)
vendor/bin/libreoffice lo:probe --binary="C:\Program Files\LibreOffice\program\soffice.exe" --temp-dir="C:\laragon\tmp"
These values are stored in src/Config/global_options.php.
lo:convert
Converts a Word document to PDF.
vendor/bin/libreoffice lo:convert "C:\docs\invoice.docx" --to=pdf --out="C:\docs\out"
Useful options:
--binary: path tosoffice--timeout: timeout in seconds--temp-dir: temporary directory--profile: strategy (none|per_job|per_worker|shared_mutex)--worker-id: worker id (forper_worker)--keep-temp: keep temporary files on failure
Usage example (code)
<?php use LibreOffice\LibreOffice; $lo = new LibreOffice(); $result = $lo->convert('C:/docs/report.docx')->to('pdf', ['output_dir' => 'C:/docs/out']); echo $result->outputPath . PHP_EOL; echo $result->durationMs . PHP_EOL; // Static usage (without instantiating): $result = LibreOffice::make()->convert('C:/docs/report.docx')->to('pdf', ['output_dir' => 'C:/docs/out']);
Test
composer test