blaspsoft/doxswap

Doxswap is a simple document conversion package for Laravel which uses LibreOffice to convert documents to a variety of formats.

0.1.0-beta 2025-03-05 13:47 UTC

This package is auto-updated.

Last update: 2025-03-06 15:40:38 UTC


README

Onym Icon

GitHub Workflow Status (main) Total Downloads Latest Version License

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.

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

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

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

Legend 🔍

  • ✅ : Supported conversion
  • Empty cell: Conversion not supported

File Type Categories 📁

  • 📝 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 🚀

License

Blasp is open-sourced software licensed under the MIT license.