定制 vsitnikov/pdflib 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vsitnikov/pdflib

Composer 安装命令:

composer require vsitnikov/pdflib

包简介

Current Release of PDFlib provide you methods to convert PDF to Images as well as Images to PDF.

README 文档

README

PDFlib is a project which enables you to interact with PDFs, Current Release provide you methods to convert PDF to Images as well as Images to PDF, future releases will included more functions to interact with PDF files

This project is an initiative of Treinetic (Pvt) Ltd, Sri Lanka. contact us via info@treinetic.com and get your project done by the experts.

Issues Software License Forks

Requirements

You should have Ghostscript >= 9.16 installed and configured.

Install

The package can be installed via composer:

$ composer require vsitnikov/pdflib

Usage

Converting a PDF to set of images.

$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();

Alternatively using chaining:

$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();

Making a PDF from set of images

$pdflib = new vsitnikov\PDFLib\PDFLib();
$imagePaths = ["images-1.jpg","images-2.jpg"];
$pdflib->makePDF($destination_pdf_file_path,$imagePaths);

If in anycase code throws '**** Unable to open the initial device, quitting.' this type of error that means program can't create temporary files because of a permission problem, this error only comes in the Linux or Mac Oparating systems so Please check the apache log and provide necessay permissions

Other useful methods

You can get the total number of pages in the 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

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Tests

  • Make sure to run all the tests and see all of them are pssing before sumbitting a pull requests

How to run Tests ?

composer install
vendor/bin/phpunit

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 36
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 38
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固