blaspsoft/doxswap
Composer 安装命令:
composer require blaspsoft/doxswap
包简介
Doxswap is a simple document conversion package for Laravel which uses LibreOffice to convert documents to a variety of formats.
关键字:
README 文档
README
Doxswap
A Laravel package for seamless document and image format conversions. Transform between various formats like DOCX -> PDF, HTML -> PDF, PNG -> WEBP, and more popular formats using a simple, elegant API. Powered by LibreOffice for documents and ImageMagick for image processing.
🚀 Features
- 📄 Multiple Format Support – Convert between documents (DOCX, XLSX, 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:
composer require blaspsoft/doxswap
You can publish the config file with:
php artisan vendor:publish --tag="doxswap-config"
Overview
The config/doxswap.php file includes:
💾 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)
📝 File Naming
Configure how output files are named using different strategies:
'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 ], ]
🛠️ Conversion Drivers
Configure paths for conversion tools:
'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 - 🪟 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, WEBP, GIF
- Web: HTML, XML
- Other: PDF
Usage
$result = Doxswap::convert('sample.docx', 'pdf'); /** * Returns a ConversionResult object with the following properties: * * @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 & ImageMagick
This package requires LibreOffice, ImageMagick, and Potrace to be installed on your system. Here's how to install them:
Ubuntu/Debian
sudo apt update sudo apt install libreoffice imagemagick potrace
macOS
brew install libreoffice imagemagick potrace
Windows
choco install libreoffice imagemagick potrace
Docker
If you're using Docker, you can add the required dependencies to your container:
# Ubuntu/Debian based RUN apt-get update && apt-get install -y libreoffice imagemagick potrace # Alpine based RUN apk add --no-cache libreoffice imagemagick potrace
PHP Requirements
- PHP >= 8.1
- ext-fileinfo
- ext-imagick
- Laravel >= 9.0
🔁 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 🔍
- ✅✅ = 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 🚀
🤝 Sponsors
If you find this package helpful, please consider sponsoring the development:
License
Blasp is open-sourced software licensed under the MIT license.
blaspsoft/doxswap 适用场景与选型建议
blaspsoft/doxswap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.59k 次下载、GitHub Stars 达 238, 最近一次更新时间为 2025 年 03 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「blaspsoft」 「doxswap」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blaspsoft/doxswap 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blaspsoft/doxswap 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blaspsoft/doxswap 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Blasp is a powerful and customisable profanity filter package for Laravel applications
Onym is a lightweight Laravel package designed to generate unique, structured, and meaningful filenames effortlessly.
SocialitePlus is a Laravel package that simplifies social authentication by extending Laravel Socialite. It provides predefined Google, Facebook, GitHub, and LinkedIn login options for seamless integration into Laravel 12 Vue and React Starter Kits
Token Forge brings Laravel Jetstream token management over to Laravel Breeze
A React & Inertia-powered API key management system for Laravel 12 React Starterkit, with secure token generation, revocation, and authentication.
A Vue & Inertia-powered API key management system for Laravel 12 Vue Starterkit, with secure token generation, revocation, and authentication.
统计信息
- 总下载量: 19.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 238
- 点击次数: 32
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-05