A 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.
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"
The config/doxswap.php
file includes:
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)
'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
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
$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
*/
This package requires LibreOffice to be installed on your system. Here's how to install it:
sudo apt update
sudo apt install libreoffice
brew install libreoffice
or download from https://www.libreoffice.org/download/download-libreoffice/
choco install libreoffice
or download from https://www.libreoffice.org/download/download-libreoffice/
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 >= 8.1
- ext-fileinfo
- Laravel >= 9.0
From/To | DOCX | ODT | RTF | TXT | HTML | EPUB | XML | XLSX | ODS | CSV | PPT | PPTX | ODP | PNG | JPG | SVG | TIFF | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DOC | β | β | β | β | β | β | β | β | ||||||||||
DOCX | β | β | β | β | β | β | β | |||||||||||
ODT | β | β | β | β | β | β | β | |||||||||||
RTF | β | β | β | β | β | β | ||||||||||||
TXT | β | β | β | β | β | |||||||||||||
HTML | β | β | β | |||||||||||||||
XML | β | β | β | β | β | |||||||||||||
CSV | β | β | β | β | ||||||||||||||
XLSX | β | β | β | β | ||||||||||||||
XLS | β | β | β | β | ||||||||||||||
ODS | β | β | β | β | ||||||||||||||
PPTX | β | β | ||||||||||||||||
PPT | β | β | ||||||||||||||||
ODP | β | β | ||||||||||||||||
SVG | β | β | β | β | ||||||||||||||
JPG | β | β | β | |||||||||||||||
PNG | β | β | β | |||||||||||||||
BMP | β | β | β | |||||||||||||||
TIFF | β | β | β |
- β : Supported conversion
- Empty cell: Conversion not supported
- π Documents: DOC, DOCX, ODT, RTF, TXT
- π Web: HTML, XML
- π Spreadsheets: XLSX, XLS, ODS, CSV
- π― Presentations: PPT, PPTX, ODP
- πΌοΈ Images: SVG, JPG, PNG, BMP, TIFF
- π eBooks: EPUB
- π Universal: PDF
Note: All conversions are performed using LibreOffice in headless mode π
Blasp is open-sourced software licensed under the MIT license.