webit/phpgs
Composer 安装命令:
composer require webit/phpgs
包简介
PHP Wrapper for Ghost Script
README 文档
README
This package provides PHP Wrapper for GhostScript. It also provides a simple tool for PDF pages splitting / merging.
Installation
composer require webit/phpgs=^1.0
Usage
Executor
For general purpose use Executor as a generic wrapper for the Ghost Script
use Webit\PHPgs\ExecutorBuilder; use Webit\PHPgs\Input; use Webit\PHPgs\Output; use Webit\PHPgs\Options\Options; use Webit\PHPgs\Options\Device; /** @var \Webit\PHPgs\Executor $executor */ $executor = ExecutorBuilder::create()->setGhostScriptBinary('/path/to/the/binary/of/gs')->build(); $input = Input::singleFile('/path/to/your/input_file'); $output = Output::create('/path/to/your/tempdir/output.pdf'); // Please note Options class is immutable (every change creates a new instance) $options = Options::create(Device::pdfWrite()) // set predefined options (see Options class for all predefined options) ->withNoTransparency() ->useCropBox() ->useCIEColor() // change any option you need ->withOption('-dWhatever', 'value of whatever'); $executor->execute($input, $output, $options);
PdfManipulator
PdfManipulator provides simplified interface for PDF splitting / merging
Merging
use Webit\PHPgs\Pdf\PdfManipulator; $pdfManipulator = new PdfManipulator($executor); $input = Input::multipleFiles( array( 'one.pdf', 'two.pdf', 'three.pdf' ) ); $output = Output::create('/temp-dir/random-5322/output.pdf'); $customOptions = Options::create(); // optional $pdfManipulator->merge($input, $output, $customOptions);
Splitting pages
use Webit\PHPgs\Pdf\PdfManipulator; $pdfManipulator = new PdfManipulator($executor); $input = Input::singleFile('multipage.pdf'); // multi page output $output = Output::create('/temp-dir/random-12322/output-%d.pdf'); // single page output // $output = Output::create('/temp-dir/random-12322/output.pdf'); $customOptions = Options::create(); // optional // splitting pages from 5 to 10 $pdfManipulator->split($input, $output, 5, 10, $customOptions); // produces output-5.pdf, output-6.pdf, ... // splitting pages from 5 to the last page $pdfManipulator->split($input, $output, 5, null, $customOptions); // produces output-5.pdf, output-6.pdf, ... // splitting pages from 1 to 10 $pdfManipulator->split($input, $output, null, 10, $customOptions); // produces output-1.pdf, output-2.pdf, ..., output-10.pdf
Note: To make sure multi-page splitting will work properly, an output always must refer to an empty directory.
Tests
docker-compose run --rm php5 ./vendor/bin/phpunit
webit/phpgs 适用场景与选型建议
webit/phpgs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.66k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ghostscript」 「ghost script」 「gs」 「pdf merge」 「pdf split」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webit/phpgs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webit/phpgs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webit/phpgs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Extension for handling CSV files
Bug-fixed and updated version of Meyfarth/Ghostscript-PHP script
PDF Merger for Nette Framework and Ghost Script.
Composer plugin for running post-install/post-update scripts of your project's dependencies
Composer script for handling the creation of symlinks for any project. Optional to provide the path or define it on the composer install if it isn't already set.
Wrapper for native lazy object in php 8.4
统计信息
- 总下载量: 2.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-01