Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
tests/Stubs/*.docx filter=lfs diff=lfs merge=lfs -text
sample.bmp filter=lfs diff=lfs merge=lfs -text
sample.csv filter=lfs diff=lfs merge=lfs -text
sample.doc filter=lfs diff=lfs merge=lfs -text
sample.html filter=lfs diff=lfs merge=lfs -text
sample.jpg filter=lfs diff=lfs merge=lfs -text
sample.odp filter=lfs diff=lfs merge=lfs -text
sample.ods filter=lfs diff=lfs merge=lfs -text
sample.odt filter=lfs diff=lfs merge=lfs -text
sample.png filter=lfs diff=lfs merge=lfs -text
sample.ppt filter=lfs diff=lfs merge=lfs -text
sample.pptx filter=lfs diff=lfs merge=lfs -text
sample.rtf filter=lfs diff=lfs merge=lfs -text
sample.svg filter=lfs diff=lfs merge=lfs -text
sample.tiff filter=lfs diff=lfs merge=lfs -text
sample.txt filter=lfs diff=lfs merge=lfs -text
sample.xls filter=lfs diff=lfs merge=lfs -text
sample.xlsx filter=lfs diff=lfs merge=lfs -text
sample.xml filter=lfs diff=lfs merge=lfs -text
sample.gif filter=lfs diff=lfs merge=lfs -text
sample.webp filter=lfs diff=lfs merge=lfs -text
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [Blaspsoft]
33 changes: 26 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,52 @@ jobs:
# Step 1: Check out the repository
- name: Checkout code
uses: actions/checkout@v4
with:
lfs: true

# Step 2: Set up PHP
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
extensions: mbstring, dom, zip
extensions: mbstring, dom, zip, fileinfo, imagick

# Step 3: Set up Git LFS
- name: Set up Git LFS
run: |
git lfs install
git lfs pull

# Step 3: Install LibreOffice (Required for Conversion)
# Step 4: List files in the repository
- name: List files
run: |
ls -lh tests/Stubs/
file --mime-type tests/Stubs/*

# Step 5: Install LibreOffice (Required for Conversion)
- name: Install LibreOffice
run: sudo apt-get update && sudo apt-get install -y libreoffice

# Step 4: Install Composer dependencies
# Step 6: Install Potrace (Required for BMP to SVG conversion)
- name: Install Potrace
run: sudo apt-get install -y potrace

# Step 7: Install Composer dependencies
- name: Install dependencies
run: composer install --no-interaction --prefer-dist

# Step 5: Set up Laravel environment (if needed)
# Step 8: Set up Laravel environment (if needed)
- name: Set up Laravel environment
run: |
echo "APP_KEY=$(php artisan key:generate --show)" > .env
echo "APP_ENV=testing" >> .env
echo "DB_CONNECTION=sqlite" >> .env
echo "LIBREOFFICE_PATH=/usr/bin/soffice" >> .env

# Step 6: Run Unit tests
# Step 9: Run Unit tests
- name: Run Unit tests
run: php ./vendor/bin/phpunit --testsuite=Unit

# Step 7: Run Integration tests (requires LibreOffice)
# Step 10: Run Integration tests (requires LibreOffice)
- name: Run Integration tests
run: php ./vendor/bin/phpunit --testsuite=Integration
run: php ./vendor/bin/phpunit --testsuite=Integration --testdox
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
composer.lock
.phpunit.result.cache
/.idea
/.idea
.DS_Store
178 changes: 111 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@

# Doxswap

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.
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.

## 🚀 Features

- 📄 **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.
- 📄 **Multiple Format Support** – Convert between documents (DOCX, PDF, ODT) and images (PNG, JPG, WEBP) with ease
- 🚀 **Simple API** – Easy-to-use interface for all conversion operations
- 💾 **Laravel Storage Integration** – Works seamlessly with Laravel's filesystem drivers
- ⚡ **Efficient Processing** – Optimized conversion using LibreOffice and ImageMagick engines
- 🔍 **Conversion Tracking** – Detailed results including duration and file paths
- 🔒 **Secure File Handling** – Safe and secure file 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:

```bash
composer require blaspsoft/doxswap:0.1.0-beta
composer require blaspsoft/doxswap
```

You can publish the config file with:
Expand All @@ -40,19 +41,43 @@ php artisan vendor:publish --tag="doxswap-config"

The `config/doxswap.php` file includes:

#### 💾 Storage
#### 💾 Storage & Cleanup

- `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
#### 📝 File Naming

Configure how output files are named using different strategies:

```php
'libre_office_path' => env('LIBRE_OFFICE_PATH', '/usr/bin/soffice')
'filename' => [
// Strategy: 'original', 'random', or 'timestamp'
'strategy' => 'original',

// Naming options
'options' => [
'length' => 24, // Length for random names
'prefix' => '', // Add prefix to filename
'suffix' => '', // Add suffix to filename
'separator' => '_', // Separator for components
'format' => 'YmdHis', // Format for timestamp strategy
],
]
```

Default paths by OS:
#### 🛠️ Conversion Drivers

Configure paths for conversion tools:

```php
'drivers' => [
'libreoffice_path' => env('LIBRE_OFFICE_PATH', '/usr/bin/soffice'),
]
```

Default LibreOffice paths by OS:

- 🐧 Linux: `/usr/bin/soffice`
- 🍎 macOS: `/Applications/LibreOffice.app/Contents/MacOS/soffice`
Expand All @@ -65,113 +90,132 @@ 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
- Images: JPG, PNG, SVG, BMP, TIFF, WEBP, GIF
- Web: HTML, XML
- Other: PDF, EPUB
- Other: PDF

### Usage

```php
$convertedFile = Doxswap::convert('sample.docx', 'pdf');
$result = Doxswap::convert('sample.docx', 'pdf');

/**
* Returns a Doxswap object with the following properties:
* Returns a ConversionResult 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
* @property string $inputFilename The original input filename
* @property string $inputFilePath The full path to the input file
* @property string $outputFilename The converted output filename
* @property string $outputFilePath The full path to the converted output file
* @property string $toFormat The format the file was converted to (e.g. 'pdf')
* @property string $duration The time taken for conversion (e.g. "2.21 sec")
* @property float $startTime Unix timestamp of when conversion started
* @property float $endTime Unix timestamp of when conversion completed
* @property string $inputDisk The Laravel storage disk used for input
* @property string $outputDisk The Laravel storage disk used for output
*/

```

## Requirements

### LibreOffice
### LibreOffice & ImageMagick

This package requires LibreOffice to be installed on your system. Here's how to install it:
This package requires LibreOffice, ImageMagick, and Potrace to be installed on your system. Here's how to install them:

#### Ubuntu/Debian

```bash
sudo apt update
sudo apt install libreoffice
sudo apt install libreoffice imagemagick potrace
```

#### macOS

```bash
brew install libreoffice
brew install libreoffice imagemagick potrace
```

# or download from https://www.libreoffice.org/download/download-libreoffice/

#### Windows

```bash
choco install libreoffice
choco install libreoffice imagemagick potrace
```

# or download from https://www.libreoffice.org/download/download-libreoffice/

#### Docker

If you're using Docker, you can add LibreOffice to your container:
If you're using Docker, you can add the required dependencies to your container:

```dockerfile
# Ubuntu/Debian based
RUN apt-get update && apt-get install -y libreoffice
RUN apt-get update && apt-get install -y libreoffice imagemagick potrace

# Alpine based
RUN apk add --no-cache libreoffice
RUN apk add --no-cache libreoffice imagemagick potrace
```

### PHP Requirements

- PHP >= 8.1
- ext-fileinfo
- ext-imagick
- Laravel >= 9.0

## Supported Conversions 📄 ↔️ 📑

| From/To | PDF | 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 Conversions by Category

### 📝 Documents

| From | Supported Conversions |
| ---- | ---------------------------------------------- |
| DOCX | PDF ✅✅, ODT, RTF, TXT, HTML, XML, EPUB |
| DOC | PDF ✅✅, DOCX, ODT, RTF, TXT, HTML, XML, EPUB |
| ODT | PDF, DOCX, RTF, TXT, HTML, XML |
| RTF | PDF, DOCX, ODT, TXT, HTML, XML |
| TXT | PDF, DOCX, ODT, HTML, XML |
| HTML | PDF, ODT, TXT |
| XML | PDF, DOCX, ODT, TXT, HTML |

### 📊 Spreadsheets

| From | Supported Conversions |
| ---- | --------------------- |
| XLSX | PDF ✅✅, ODS, CSV |
| XLS | PDF, XLSX, ODS, CSV |
| ODS | PDF, XLSX, CSV |
| CSV | PDF, XLSX, ODS |

### 🎯 Presentations

| From | Supported Conversions |
| ---- | --------------------- |
| PPTX | PDF ✅✅, ODP |
| PPT | PDF, PPTX, ODP |
| ODP | PDF, PPTX |

### 🖼️ Images

| From | Supported Conversions |
| ---- | -------------------------------------- |
| PNG | PDF ✅, JPG, SVG, TIFF, WEBP, GIF, BMP |
| JPG | PDF ✅, PNG, SVG, TIFF, WEBP, GIF, BMP |
| SVG | PDF, PNG, JPG, TIFF, WEBP, GIF, BMP |
| BMP | PDF, PNG, JPG, SVG, TIFF, WEBP, GIF |
| TIFF | PDF, PNG, JPG, SVG, WEBP, GIF, BMP |
| WEBP | PDF, PNG, JPG, SVG, TIFF, GIF, BMP |
| GIF | PDF, PNG, JPG, SVG, TIFF, WEBP, BMP |

### Legend 🔍

- ✅ : Supported conversion
- Empty cell: Conversion not supported
- ✅✅ = Common high-priority conversion
- ✅ = Popular supported format
- (unlisted) = Conversion not supported

> **Note**: Document conversions are performed using LibreOffice in headless mode, while image format conversions utilize ImageMagick 🚀

### File Type Categories 📁
## 🤝 Sponsors

- 📝 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
If you find this package helpful, please consider sponsoring the development:

> **Note**: All conversions are performed using LibreOffice in headless mode 🚀
> 🚀 [Become a GitHub Sponsor](https://github.com/sponsors/Blaspsoft)

## License

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "blaspsoft/doxswap",
"description": "Doxswap is a simple document conversion package for Laravel which uses LibreOffice to convert documents to a variety of formats.",
"version": "0.1.0-beta",
"version": "dev-main",
"keywords": [
"blaspsoft",
"doxswap"
Expand All @@ -18,7 +18,7 @@
],
"require": {
"php": "^8.2",
"blaspsoft/onym": "^1.0",
"blaspsoft/onym": "dev-main",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0|^12.0"
},
"require-dev": {
Expand Down
Loading