1010
1111# Doxswap
1212
13- 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.
13+ A Laravel package for seamless document and image format conversions. Transform between various formats like DOCX, PDF, ODT, and popular image formats using a simple, elegant API. Powered by LibreOffice for documents and ImageMagick for image processing .
1414
1515## 🚀 Features
1616
17- - 📄 ** Multiple Format Support** – Convert between DOCX, PDF, ODT, and other document formats.
18- - 🚀 ** Simple API** – Easy-to-use interface for document conversion operations.
19- - 💾 ** Laravel Storage Integration** – Works seamlessly with Laravel's filesystem drivers.
20- - ⚡ ** Efficient Processing** – Optimized conversion using LibreOffice's powerful engine.
21- - 🔒 ** Secure File Handling** – Safe and secure document processing with proper cleanup.
22- - ⚙️ ** Configurable Settings** – Customize paths, storage disks, and conversion options.
23- - 🛡️ ** Error Handling** – Robust exception handling for unsupported formats and conversions.
17+ - 📄 ** Multiple Format Support** – Convert between documents (DOCX, PDF, ODT) and images (PNG, JPG, WEBP) with ease
18+ - 🚀 ** Simple API** – Easy-to-use interface for all conversion operations
19+ - 💾 ** Laravel Storage Integration** – Works seamlessly with Laravel's filesystem drivers
20+ - ⚡ ** Efficient Processing** – Optimized conversion using LibreOffice and ImageMagick engines
21+ - 🔍 ** Conversion Tracking** – Detailed results including duration and file paths
22+ - 🔒 ** Secure File Handling** – Safe and secure file processing with proper cleanup
23+ - ⚙️ ** Configurable Settings** – Customize paths, storage disks, and conversion options
24+ - 🛡️ ** Error Handling** – Robust exception handling for unsupported formats and conversions
2425
2526## Installation
2627
2728You can install the package via composer:
2829
2930``` bash
30- composer require blaspsoft/doxswap:0.1.0-beta
31+ composer require blaspsoft/doxswap
3132```
3233
3334You can publish the config file with:
@@ -40,19 +41,43 @@ php artisan vendor:publish --tag="doxswap-config"
4041
4142The ` config/doxswap.php ` file includes:
4243
43- #### 💾 Storage
44+ #### 💾 Storage & Cleanup
4445
4546- ` input_disk ` : Where to read files from (default: 'public')
4647- ` output_disk ` : Where to save converted files (default: 'public')
4748- ` perform_cleanup ` : Delete input files after conversion (default: false)
4849
49- #### 🛠️ LibreOffice Path
50+ #### 📝 File Naming
51+
52+ Configure how output files are named using different strategies:
53+
54+ ``` php
55+ 'filename' => [
56+ // Strategy: 'original', 'random', or 'timestamp'
57+ 'strategy' => 'original',
58+
59+ // Naming options
60+ 'options' => [
61+ 'length' => 24, // Length for random names
62+ 'prefix' => '', // Add prefix to filename
63+ 'suffix' => '', // Add suffix to filename
64+ 'separator' => '_', // Separator for components
65+ 'format' => 'YmdHis', // Format for timestamp strategy
66+ ],
67+ ]
68+ ```
69+
70+ #### 🛠️ Conversion Drivers
71+
72+ Configure paths for conversion tools:
5073
5174``` php
52- 'libre_office_path' => env('LIBRE_OFFICE_PATH', '/usr/bin/soffice')
75+ 'drivers' => [
76+ 'libreoffice_path' => env('LIBRE_OFFICE_PATH', '/usr/bin/soffice'),
77+ ]
5378```
5479
55- Default paths by OS:
80+ Default LibreOffice paths by OS:
5681
5782- 🐧 Linux: ` /usr/bin/soffice `
5883- 🍎 macOS: ` /Applications/LibreOffice.app/Contents/MacOS/soffice `
@@ -65,113 +90,130 @@ Supports various document formats including:
6590- Documents: DOC, DOCX, ODT, RTF, TXT
6691- Spreadsheets: XLS, XLSX, ODS, CSV
6792- Presentations: PPT, PPTX, ODP
68- - Images: JPG, PNG, SVG, BMP, TIFF
93+ - Images: JPG, PNG, SVG, BMP, TIFF, WEBP, GIF
6994- Web: HTML, XML
70- - Other: PDF, EPUB
95+ - Other: PDF
7196
7297### Usage
7398
7499``` php
75- $convertedFile = Doxswap::convert('sample.docx', 'pdf');
100+ $result = Doxswap::convert('sample.docx', 'pdf');
76101
77102/**
78- * Returns a Doxswap object with the following properties:
103+ * Returns a ConversionResult object with the following properties:
79104 *
80- * @property string $inputFile The original input filename
81- * @property string $outputFile The full path to the converted output file
82- * @property string $toFormat The format the file was converted to (e.g. 'pdf')
83- * @property ConversionService $conversionService The service used for conversion
105+ * @property string $inputFilename The original input filename
106+ * @property string $inputFilePath The full path to the input file
107+ * @property string $outputFilename The converted output filename
108+ * @property string $outputFilePath The full path to the converted output file
109+ * @property string $toFormat The format the file was converted to (e.g. 'pdf')
110+ * @property string $duration The time taken for conversion (e.g. "2.21 sec")
111+ * @property float $startTime Unix timestamp of when conversion started
112+ * @property float $endTime Unix timestamp of when conversion completed
113+ * @property string $inputDisk The Laravel storage disk used for input
114+ * @property string $outputDisk The Laravel storage disk used for output
84115 */
85116
86117```
87118
88119## Requirements
89120
90- ### LibreOffice
121+ ### LibreOffice & ImageMagick
91122
92- This package requires LibreOffice to be installed on your system. Here's how to install it :
123+ This package requires LibreOffice and ImageMagick to be installed on your system. Here's how to install them :
93124
94125#### Ubuntu/Debian
95126
96127``` bash
97128sudo apt update
98- sudo apt install libreoffice
129+ sudo apt install libreoffice imagemagick
99130```
100131
101132#### macOS
102133
103134``` bash
104- brew install libreoffice
135+ brew install libreoffice imagemagick
105136```
106137
107- # or download from https://www.libreoffice.org/download/download-libreoffice/
138+ # or download LibreOffice from https://www.libreoffice.org/download/download-libreoffice/
108139
109140#### Windows
110141
111142``` bash
112- choco install libreoffice
143+ choco install libreoffice imagemagick
113144```
114145
115- # or download from https://www.libreoffice.org/download/download-libreoffice/
146+ # or download LibreOffice from https://www.libreoffice.org/download/download-libreoffice/
116147
117148#### Docker
118149
119- If you're using Docker, you can add LibreOffice to your container:
150+ If you're using Docker, you can add the required dependencies to your container:
120151
121152``` dockerfile
122153# Ubuntu/Debian based
123- RUN apt-get update && apt-get install -y libreoffice
154+ RUN apt-get update && apt-get install -y libreoffice imagemagick
124155
125156# Alpine based
126- RUN apk add --no-cache libreoffice
157+ RUN apk add --no-cache libreoffice imagemagick
127158```
128159
129160### PHP Requirements
130161
131162- PHP >= 8.1
132163- ext-fileinfo
164+ - ext-imagick
133165- Laravel >= 9.0
134166
135- ## Supported Conversions 📄 ↔️ 📑
136-
137- | From/To | PDF | DOCX | ODT | RTF | TXT | HTML | EPUB | XML | XLSX | ODS | CSV | PPT | PPTX | ODP | PNG | JPG | SVG | TIFF |
138- | ------- | :-: | :--: | :-: | :-: | :-: | :--: | :--: | :-: | :--: | :-: | :-: | :-: | :--: | :-: | :-: | :-: | :-: | :--: |
139- | DOC | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | |
140- | DOCX | ✅ | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | |
141- | ODT | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | ✅ | | | | | | | | | | |
142- | RTF | ✅ | ✅ | ✅ | | ✅ | ✅ | | ✅ | | | | | | | | | | |
143- | TXT | ✅ | ✅ | ✅ | | | ✅ | | ✅ | | | | | | | | | | |
144- | HTML | ✅ | | ✅ | | ✅ | | | | | | | | | | | | | |
145- | XML | ✅ | ✅ | ✅ | | ✅ | ✅ | | | | | | | | | | | | |
146- | CSV | ✅ | | | | | ✅ | | | ✅ | ✅ | | | | | | | | |
147- | XLSX | ✅ | | | | | ✅ | | | | ✅ | ✅ | | | | | | | |
148- | XLS | ✅ | | | | | ✅ | | | | ✅ | ✅ | | | | | | | |
149- | ODS | ✅ | | | | | ✅ | | | ✅ | | ✅ | | | | | | | |
150- | PPTX | ✅ | | | | | | | | | | | | | ✅ | | | | |
151- | PPT | ✅ | | | | | | | | | | | | | ✅ | | | | |
152- | ODP | ✅ | | | | | | | | | | | | ✅ | | | | | |
153- | SVG | ✅ | | | | | | | | | | | | | | ✅ | ✅ | | ✅ |
154- | JPG | ✅ | | | | | | | | | | | | | | ✅ | | ✅ | |
155- | PNG | ✅ | | | | | | | | | | | | | | | ✅ | ✅ | |
156- | BMP | ✅ | | | | | | | | | | | | | | ✅ | ✅ | | |
157- | TIFF | ✅ | | | | | | | | | | | | | | ✅ | ✅ | | |
167+ ## 🔁 Supported Conversions by Category
168+
169+ ### 📝 Documents
170+
171+ | From | Supported Conversions |
172+ | ---- | ---------------------------------------------- |
173+ | DOCX | PDF ✅✅, ODT, RTF, TXT, HTML, XML, EPUB |
174+ | DOC | PDF ✅✅, DOCX, ODT, RTF, TXT, HTML, XML, EPUB |
175+ | ODT | PDF, DOCX, RTF, TXT, HTML, XML |
176+ | RTF | PDF, DOCX, ODT, TXT, HTML, XML |
177+ | TXT | PDF, DOCX, ODT, HTML, XML |
178+ | HTML | PDF, ODT, TXT |
179+ | XML | PDF, DOCX, ODT, TXT, HTML |
180+
181+ ### 📊 Spreadsheets
182+
183+ | From | Supported Conversions |
184+ | ---- | --------------------- |
185+ | XLSX | PDF ✅✅, ODS, CSV |
186+ | XLS | PDF, XLSX, ODS, CSV |
187+ | ODS | PDF, XLSX, CSV |
188+ | CSV | PDF, XLSX, ODS |
189+
190+ ### 🎯 Presentations
191+
192+ | From | Supported Conversions |
193+ | ---- | --------------------- |
194+ | PPTX | PDF ✅✅, ODP |
195+ | PPT | PDF, PPTX, ODP |
196+ | ODP | PDF, PPTX |
197+
198+ ### 🖼️ Images
199+
200+ | From | Supported Conversions |
201+ | ---- | -------------------------------------- |
202+ | PNG | PDF ✅, JPG, SVG, TIFF, WEBP, GIF, BMP |
203+ | JPG | PDF ✅, PNG, SVG, TIFF, WEBP, GIF, BMP |
204+ | SVG | PDF, PNG, JPG, TIFF, WEBP, GIF, BMP |
205+ | BMP | PDF, PNG, JPG, SVG, TIFF, WEBP, GIF |
206+ | TIFF | PDF, PNG, JPG, SVG, WEBP, GIF, BMP |
207+ | WEBP | PDF, PNG, JPG, SVG, TIFF, GIF, BMP |
208+ | GIF | PDF, PNG, JPG, SVG, TIFF, WEBP, BMP |
158209
159210### Legend 🔍
160211
161- - ✅ : Supported conversion
162- - Empty cell: Conversion not supported
163-
164- ### File Type Categories 📁
165-
166- - 📝 Documents: DOC, DOCX, ODT, RTF, TXT
167- - 🌐 Web: HTML, XML
168- - 📊 Spreadsheets: XLSX, XLS, ODS, CSV
169- - 🎯 Presentations: PPT, PPTX, ODP
170- - 🖼️ Images: SVG, JPG, PNG, BMP, TIFF
171- - 📚 eBooks: EPUB
172- - 📄 Universal: PDF
212+ - ✅✅ = Common high-priority conversion
213+ - ✅ = Popular supported format
214+ - (unlisted) = Conversion not supported
173215
174- > ** Note** : All conversions are performed using LibreOffice in headless mode 🚀
216+ > ** Note** : Document conversions are performed using LibreOffice in headless mode, while image format conversions utilize ImageMagick 🚀
175217
176218## License
177219
0 commit comments