Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pdf Optimizer Laravel Package

mostafaznv/pdf-optimizer

Optimize and compress PDFs in PHP or Laravel using Ghostscript. Fluent API with extensive option support, logging, and customization. Works with file paths, UploadedFile, and storage disks, with optional queue support for async optimization.

View on GitHub
Deep Wiki
Context7

Getting Started

Install Ghostscript first—this is required but not bundled (you must handle licensing). On Ubuntu: sudo apt install ghostscript. Then install the package: composer require mostafaznv/pdf-optimizer. For Laravel, run php artisan vendor:publish --provider="Mostafaznv\PdfOptimizer\PdfOptimizerServiceProvider". Your first use case: compress an uploaded PDF before saving it—e.g., after a user submits a report.

Implementation Patterns

Use fluent method chaining for clarity and control: chain settings (e.g., PdfSettings::PREPRESS), resolutions, and strategies (e.g., ColorConversionStrategy::DEVICE_INDEPENDENT_COLOR). Leverage Laravel-specific helpers: PdfOptimizer::fromDisk('local')->open($file)->toDisk('s3')->optimize(). For background processing, dispatch jobs using ->queue() ( Laravel’s queue workers handle the async execution). Combine with filesystem events (e.g., Storage::after() or model observers) to auto-optimize on upload. Use the logger() method or custom PSR-3 logger to track file sizes before/after and handle errors gracefully.

Gotchas and Tips

Ghostscript must be correctly installed and accessible via CLI—verify with which gs or whereis ghostscript. If optimization fails, check exit codes and logs; default timeouts can be too short for large files—tune via timeout(120). Windows support is untested—avoid production deployments there unless thoroughly validated. Beware Ghostscript’s AGPL licensing: if you distribute your app, you may need a commercial license or comply with AGPL. In Laravel, the config file (config/pdf-optimizer.php) lets you define defaults and binary paths—use env vars (GS_BINARY_PATH) for deployment-specific overrides. For debugging, temporarily switch to PdfSettings::PREPRESS for high quality and check intermediate logs to spot resolution/filters causing bloat.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport