Knowledge Base

Empty filter

Laravel package for seamless document conversion using LibreOffice

Convert between various document formats like DOCX, PDF, ODT and more with a simple, elegant API.


📄 Multiple Format Support – Convert between DOCX, PDF, ODT, and other document formats.
🚀 Simple API – Easy-to-use interface for document conversion operations.
💾 Laravel Storage Integration – Works seamlessly with Laravel's filesystem drivers.
⚡ Efficient Processing – Optimized conversion using LibreOffice's powerful engine.
🔒 Secure File Handling – Safe and secure document processing with proper cleanup.
⚙️ Configurable Settings – Customize paths, storage disks, and conversion options.
🛡️ Error Handling – Robust exception handling for unsupported formats and conversions.
Installation
You can install the package via composer:

composer require blaspsoft/doxswap:0.1.0-beta
You can publish the config file with:

php artisan vendor:publish --tag="doxswap-config"
Overview
The config/doxswap.php file includes:

💾 Storage
input_disk: Where to read files from (default: 'public')
output_disk: Where to save converted files (default: 'public')
perform_cleanup: Delete input files after conversion (default: false)
🛠️ LibreOffice Path
'libre_office_path' => env('LIBRE_OFFICE_PATH', '/usr/bin/soffice')
Default paths by OS:

🐧 Linux: /usr/bin/soffice
🍎 macOS: /Applications/LibreOffice.app/Contents/MacOS/soffice
🪟 Windows: C:\Program Files\LibreOffice\program\soffice.exe
📄 File Types
Supports various document formats including:

Documents: DOC, DOCX, ODT, RTF, TXT
Spreadsheets: XLS, XLSX, ODS, CSV
Presentations: PPT, PPTX, ODP
Images: JPG, PNG, SVG, BMP, TIFF
Web: HTML, XML
Other: PDF, EPUB
Usage
$convertedFile = Doxswap::convert('sample.docx', 'pdf');

/**
* Returns a Doxswap object with the following properties:
*
* @property string $inputFile The original input filename
* @property string $outputFile The full path to the converted output file
* @property string $toFormat The format the file was converted to (e.g. 'pdf')
* @property ConversionService $conversionService The service used for conversion
*/
Requirements
LibreOffice
This package requires LibreOffice to be installed on your system. Here's how to install it:

Ubuntu/Debian
sudo apt update
sudo apt install libreoffice
macOS
brew install libreoffice
or download from https://www.libreoffice.org/download/download-libreoffice/
Windows
choco install libreoffice
or download from https://www.libreoffice.org/download/download-libreoffice/
Docker
If you're using Docker, you can add LibreOffice to your container:

# Ubuntu/Debian based
RUN apt-get update && apt-get install -y libreoffice

# Alpine based
RUN apk add --no-cache libreoffice
PHP Requirements
PHP >= 8.1
ext-fileinfo
Laravel >= 9.0

Published
Back to Index