wmlc / pdf2image
Convert pdf files to images
Requires
- ext-imagick: *
- intervention/image: ^2.0
README
laravel-pdf-to-image
Convert pdf files to images for Laravel 5
Laravel 5下的 PDF 转图片工具包,
本包提供了Laravel 5 把pdf文件转换为图片的功能, 同时基于Laravel Storage 对生成的图片进行存储和管理。
功能列表:
- 按页转换PDF文件为图片,每页生成1张图片
- 保存到指定的存储空间
- 支持云存储(测试中)
- 支持定时任务后台转换图片(开发中)
- 支持队列转换图片(开发中)
依赖 Package dependencies
必须安装扩展包,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' "
安装Installation:
composer require wmlc/pdf2image
Laravel >= 5.5, after install nothing left to do.
Laravel <5.5
Add a provider in providers array in config/app.php:
wmlc\Pdf2Image\Pdf2ImageMaker::class,
Add a aliase in aliases array:
'PdfToImage'=>wmlc\Pdf2Image\Pdf2ImageFacade::class,
用法
Get pdf file pages count
use Pdf2Image;
$pageCount = Pdf2Image::pdfFile(public_path() . "/imgs/test.pdf")->totalPages();
Pdf all page to imgs
use Pdf2Image;
Pdf2Image::pdfFile(public_path() . "/imgs/test.pdf")->saveImages();
Pdf one page to img
use Pdf2Image;
Pdf2Image::pdfFile(public_path() . "/imgs/test.pdf")->saveImage(0);