Convert pdf files to images for Laravel.
Laravel 框架下的 PDF 转图片工具包,
本包提供了Laravel 把pdf文件转换为图片的功能, 同时基于Laravel Storage 对生成的图片进行存储和管理。
- 按页转换PDF文件为图片,每页生成1张图片
- Convert every page of PDF fiel to one image.
- 保存到指定的存储空间
- Save images to disk of Storage
- 支持云存储(测试中)
- Save image to cloud disk.(Developing)
- 支持定时任务后台转换图片(开发中)
- Convert PDF file to images by cron task.(Developing)
必须安装扩展包,You must install package imagick, 参考信息 more info: http://php.net/manual/en/book.imagick.php http://php.net/manual/en/imagick.setup.php
"ext-imagick" : "*",
"intervention/image": "^2.0",
"illuminate/support": "5.*"
执行 run: php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
then: you will find a new file image.php in folder config. Change " 'driver' => 'gd' " to " 'driver' => 'imagick' "
composer require jianhuawang/laravel-pdf-to-image:^0.4
Add a provider in providers array in config/app.php:
JianhuaWang\PdfToImage\PdfToImageMaker::class,
Add a aliase in aliases array:
'PdfToImage'=>JianhuaWang\PdfToImage\PdfToImageFacade::class,
-
Following code will read pdf file on (project root) + /storage/app/test.pdf, and convert first page to image, the image will be saved on (project root) + /storage/app/(current date)/(seconds).jpg
$pdfFileNameWithPath='test.pdf';
$converter=new JianhuaWang\PdfToImage\PdfToImageMaker($pdfFileNameWithPath);
$converter->saveImage();// Default action is converting all pages to images.
-
The following codes has same function with above.
use PdfToImage; PdfToImage::pdfFile('test.pdf')->saveImage();