vsitnikov / pdflib
PDFlib的当前版本提供了将PDF转换为图像以及将图像转换为PDF的方法。
1.3.1
2020-02-28 05:21 UTC
Requires
- php: >=5.5.0
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
README
PDFlib是一个项目,使您能够与PDF文件交互,当前版本提供将PDF转换为图像以及将图像转换为PDF的方法,未来的版本将包含更多与PDF文件交互的功能。
该项目是斯里兰卡Treinetic (Pvt) Ltd的倡议,通过info@treinetic.com联系我们,并由专家完成您的项目。
要求
您应该已安装并配置Ghostscript >= 9.16。
安装
可以通过composer安装此包。
$ composer require vsitnikov/pdflib
用法
将PDF转换为图像集。
$pdflib = new vsitnikov\PDFLib\PDFLib(); $pdflib->setPdfPath($pdf_file_path); $pdflib->setOutputPath($folder_path_for_images); $pdflib->setImageFormat(\vsitnikov\PDFLib\PDFLib::$IMAGE_FORMAT_PNG); $pdflib->setDPI(300); $pdflib->setPageRange(1,$pdflib->getNumberOfPages()); $pdflib->setFilePrefix('page-'); // Optional $pdflib->convert();
或者使用链式调用
$files = (new vsitnikov\PDFLib\PDFLib()) ->setPdfPath($pdf_file_path) ->setOutputPath($folder_path_for_images) ->setImageFormat(\vsitnikov\PDFLib\PDFLib::$IMAGE_FORMAT_PNG) ->setDPI(300) ->setPageRange(1,$pdflib->getNumberOfPages()) ->setFilePrefix('page-') // Optional ->convert();
从图像集制作PDF
$pdflib = new vsitnikov\PDFLib\PDFLib(); $imagePaths = ["images-1.jpg","images-2.jpg"]; $pdflib->makePDF($destination_pdf_file_path,$imagePaths);
如果在任何情况下代码抛出'****无法打开初始设备,退出'此类错误,这意味着程序无法创建临时文件,因为权限问题,此错误仅出现在Linux或Mac操作系统上,因此请检查apache日志并提供必要权限
其他有用的方法
您可以得到PDF中的总页数
$pdfBox->getNumberOfPages(); //returns the number of pages in the pdf $pdfBox->setPageRange(1,2); // allows you to convert only few pages in the PDF Document $pdfBox->setImageQuality(95); // allows you to tell the quality you expect in the output Jpg file (only jpg) $pdfBox->setDPI(300); //setting the DPI (Dots per inch) of output files $pdfLib->setImageFormat(\vsitnikov\PDFLib\PDFLib::$IMAGE_FORMAT_PNG,$dDownScaleFactor=null); //this will set the output image format, default it is jpg, but I recommend using pdf to png because it seems it is faster /* $dDownScaleFactor=integer This causes the internal rendering to be scaled down by the given (integer <= 8) factor before being output. For example, the following will produce a 200dpi output png from a 600dpi internal rendering: gs -sDEVICE=png16m -r600 -dDownScaleFactor=3 -o tiger.png\examples/tiger.png Read More : http://ghostscript.com/doc/current/Devices.htm */
变更日志
请参阅CHANGELOG以获取更多最近更改的信息。
贡献
请参阅CONTRIBUTING以获取详细信息。
测试
- 确保在提交pull请求之前运行所有测试并查看所有测试都通过。
如何运行测试?
composer install
vendor/bin/phpunit
鸣谢
许可协议
MIT许可(MIT)。有关更多信息,请参阅许可文件。