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 To Image

Pdf To Image Laravel Package

spatie/pdf-to-image

View on GitHub
Deep Wiki
Context7

Convert a pdf to an image

Frequently asked questions about Pdf To Image
How do I install and configure spatie/pdf-to-image in a Laravel project?
Run `composer require spatie/pdf-to-image` and ensure your server has Imagick and Ghostscript installed. No additional Laravel configuration is needed beyond PHP 8.2+. Check the [GitHub issues](https://github.com/spatie/pdf-to-image/issues) for troubleshooting Ghostscript/Imagick setup.
Can I convert multi-page PDFs to individual images?
Yes, the package supports multi-page PDFs. Use `selectPage($pageNumber)` to target specific pages or loop through pages to save each as a separate image. The `save()` method returns an array of filenames for multi-page outputs.
What Laravel versions and PHP versions does this package support?
This package requires PHP 8.2+ and is compatible with Laravel 10+. For PHP < 8.2, use version 2.0 of the package. Always align with Laravel’s LTS releases to avoid compatibility risks.
How do I handle large PDFs (e.g., 100MB+) without timing out?
For large files, use Laravel Queues to offload conversion to a background job (e.g., `PdfToImageJob`). Test performance with your specific PDFs and adjust Imagick’s memory limits or consider chunked processing for multi-page files.
Is it safe to use this package with user-uploaded PDFs?
Yes, but validate PDF paths to prevent directory traversal attacks. Avoid processing remote PDFs (use local storage). Integrate with Laravel’s `ValidatesWhen` or `FormRequest` to restrict file types/sizes (e.g., `mimes:pdf`, `max:50000` for 50MB).
How can I save converted images to Laravel’s storage system?
Use Laravel’s `Storage` facade to save images. For example: `$pdf->save(storage_path('app/public/converted.jpg'))` or leverage `Storage::disk('public')->put()` for web-accessible files. Avoid storing images directly in the database; use filesystem or CDN.
What image formats are supported, and how do I specify them?
Supported formats are `jpg`, `jpeg`, `png`, and `webp`. Omit the extension to default to `jpg`. Use `selectFormat('png')` before saving to enforce a specific format. Check `isValidOutputFormat('format')` to validate formats programmatically.
How do I customize image quality or resolution?
Use `quality($value)` to set JPEG/PNG quality (1–100) and `resolution($dpi)` to adjust DPI. Example: `$pdf->quality(90)->resolution(300)->save()`. Defaults are typically sufficient for most use cases, but test edge cases like vector-heavy PDFs.
Can I integrate this with Laravel Notifications or Events?
Yes. Dispatch custom events (e.g., `PdfConverted`) after conversion to trigger notifications or post-processing. For async jobs, use Laravel’s `dispatch()` in your job’s `handle()` method. Example: `event(new PdfConverted($imagePath));`
What alternatives exist if Ghostscript/Imagick aren’t available?
Consider Symfony’s `Dompdf` (for HTML-to-PDF reverse workflows) or FFmpeg-based solutions (e.g., `barryvdh/laravel-snappy`). However, these may not match the quality or flexibility of Imagick/Ghostscript. Document your fallback strategy in the README.
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
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