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

Pdf Optimizer Laravel Package

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.

View on GitHub
Deep Wiki
Context7

PDF optimization tool for PHP and Laravel applications

Frequently asked questions about Pdf Optimizer
How do I install and use this package in Laravel for PDF compression?
First, require the package via Composer: `composer require mostafaznv/pdf-optimizer`. Then, use the facade in your code: `PdfOptimizer::fromDisk('s3')->open('file.pdf')->optimize()`. The package supports Laravel’s Storage facade out of the box, so you can directly work with local or cloud storage.
Does this package support Laravel queues for async PDF optimization?
Yes, the package integrates with Laravel queues. Wrap your optimization logic in a job (e.g., `OptimizePdfJob`) and use `shouldQueue()` to process PDFs asynchronously. This is ideal for reducing server load during peak times or handling large batches of files.
What Laravel versions are compatible with this package?
The package supports Laravel 9+ and requires PHP 8.2+. It works with any Laravel version that adheres to these requirements, as it doesn’t impose additional Laravel-specific constraints beyond Composer compatibility.
How do I handle UploadedFile instances from Laravel forms or APIs?
The package directly supports Laravel’s `UploadedFile` instances. Pass the file to the optimizer using `PdfOptimizer::fromUploadedFile($request->file('pdf'))->optimize()`. This eliminates the need for manual file handling or temporary storage.
What Ghostscript options can I customize in this package?
You can fine-tune nearly all Ghostscript options, such as resolution, color strategies, and compression levels. Use methods like `setResolution(300)` or `setCompression(true)` in your chain to customize the optimization process before calling `optimize()`.
Is there a way to log optimization errors or failures in Laravel?
Yes, the package includes built-in logger support. You can integrate it with Laravel’s logging system to track errors, such as corrupted PDFs or Ghostscript failures. Configure the logger in the published config file after running `php artisan vendor:publish`.
What are the licensing implications of using Ghostscript with this package?
Ghostscript is licensed under AGPL, which requires your entire application to be open-source if you use the open-source version. If your project is proprietary, consider purchasing a commercial Ghostscript license. Always audit the license terms before deployment.
How do I ensure Ghostscript is installed and up-to-date across all environments?
Ghostscript must be pre-installed on all servers, including dev, staging, and production. Use tools like Docker or configuration management (e.g., Ansible) to standardize installations. Test the `ghostscript --version` command in your CI/CD pipeline to verify compatibility.
Are there performance considerations when optimizing large PDFs?
Ghostscript is resource-intensive, especially for large or complex PDFs (e.g., 100MB+). Benchmark your server’s CPU and memory usage during optimization. For bulk processing, use Laravel queues to distribute the load and monitor queue backlogs to avoid bottlenecks.
What alternatives exist if Ghostscript isn’t feasible for my project?
If Ghostscript’s licensing or installation is problematic, consider alternatives like `setasign/fpdf` for PDF generation (not optimization) or cloud-based services like Adobe Acrobat API. However, these may lack the fine-grained control and cost-effectiveness of Ghostscript for optimization.
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata