mostafaznv/pdf-optimizer
Optimize and compress PDFs in PHP or Laravel using Ghostscript. Fluent, chainable API with rich options, logging, and customization. Laravel-friendly inputs (paths, uploads, disks) plus queue support for async optimization.
Cost Efficiency & Performance Optimization:
Build vs. Buy:
User Experience (UX) Enhancements:
Compliance & Accessibility:
EmbedAllFonts and ColorConversionStrategy options can be configured to align with compliance requirements.Scalability:
pdf-optimization) to avoid blocking HTTP requests.Adopt This Package If:
Look Elsewhere If:
setasign/fpdf or spatie/pdf-to-text."This package lets us reduce PDF file sizes by up to 70% using open-source Ghostscript, cutting storage costs and improving upload/download speeds for our [target user base, e.g., customers, employees, or partners]. By integrating it into our Laravel stack, we avoid vendor lock-in and licensing fees while enhancing performance for features like [document uploads, e-signatures, or report generation]. The async queue support ensures scalability without degrading user experience. Initial setup is minimal—just install Ghostscript and a Composer package—and the ROI comes from immediate storage savings and faster workflows."
Key Metrics to Track:
*"This package provides a production-ready, Laravel-native wrapper for Ghostscript, solving our PDF optimization needs with:
- Fluent API: Chainable methods for fine-grained control over compression (e.g., resolution, color strategies, font embedding).
- Queue Integration: Offload heavy PDF processing to background workers, avoiding timeouts and improving responsiveness.
- Multi-Source Support: Handle files from disks,
UploadedFileinstances, or cloud storage (S3, etc.) seamlessly.- Logger & Customization: Debug optimization jobs and tweak Ghostscript options without deep CLI expertise.
Why not build it ourselves?
- Ghostscript is complex; this package abstracts it into a clean, tested API.
- We’d spend weeks reinventing the wheel; this is battle-tested with 171 GitHub stars.
- The MIT license and Ghostscript’s AGPL (with commercial alternatives) align with our licensing strategy.
Proposed Rollout:
- Pilot in [high-impact feature, e.g., document uploads or report generation].
- Benchmark storage savings and performance gains.
- Expand to batch jobs (e.g., nightly PDF compression for archived files)."*
Engineering Considerations:
*"Here’s how you’ll use this package in Laravel:
Basic Usage (Sync):
use Mostafaznv\PdfOptimizer\Facades\PdfOptimizer; $result = PdfOptimizer::fromDisk('s3') ->open('large-document.pdf') ->settings(PdfSettings::SCREEN) // Optimize for digital display ->colorImageResolution(72) // Reduce resolution for web ->optimize('optimized-' . time() . '.pdf'); if ($result->status) { // Success! File is now smaller and faster to process. }Async Usage (Queue):
// Dispatch a job to optimize a PDF in the background. OptimizePdfJob::dispatch($filePath, $optimizedPath, [ 'settings' => PdfSettings::PRINT, 'resolution' => 150, ]);Key Features for You:
- No Ghostscript CLI knowledge needed: The package handles all the heavy lifting.
- Laravel disks: Works with
local,s3,ftp, etc., out of the box.- Custom Ghostscript options: Need to tweak compression? The docs list 50+ configurable options.
- Logging: Debug issues with built-in logger support.
Gotchas:
- Ghostscript must be installed on your server (Ubuntu:
sudo apt install ghostscript).- Windows support is untested—stick to Linux/MacOS for now.
- AGPL license: Ensure your app complies if using open-source Ghostscript (or buy a commercial license).
Next Steps:
- Add Ghostscript to your
Dockerfileor server.- Install the package:
composer require mostafaznv/pdf-optimizer.- Publish the config:
php artisan vendor:publish --provider="Mostafaznv\PdfOptimizer\PdfOptimizerServiceProvider".- Start optimizing!"*
How can I help you explore Laravel packages today?