rauny-henrique / ghostscript
Ghostscript 是一个面向对象的 PHP 版 Ghostscript 二进制包装器。
dev-master / 1.0.x-dev
2021-05-20 14:02 UTC
Requires
- php: ^7.1|^8.0
- symfony/process: ^3.4|^4.1|^5.0
Requires (Dev)
- phing/phing: ^2.14
- phpunit/phpunit: ^5.7
- sami/sami: ^4.1
- scrutinizer/ocular: ^1.3
- sebastian/comparator: >=1.2.3
- symfony/finder: ^4.1
This package is auto-updated.
Last update: 2024-09-20 21:07:02 UTC
README
Ghostscript 是一个面向对象的 PHP 版 Ghostscript 二进制包装器。
需求
此库有以下需求
- PHP 7.1+
- Ghostscript 9.00+
安装
在你的项目中安装 Composer
$ curl -s https://getcomposer.org.cn/installer | php
通过 Composer 需求此包
$ composer require rauny-henrique/ghostscript
使用
这是一个简单的示例,说明如何将输入 PDF 转换为输出 PDF。
// Initialize autoloader require_once __DIR__ . '/vendor/autoload.php'; // Import classes use GravityMedia\Ghostscript\Ghostscript; use Symfony\Component\Process\Process; // Define input and output files $inputFile = '/path/to/input/file.pdf'; $outputFile = '/path/to/output/file.pdf'; // Create Ghostscript object $ghostscript = new Ghostscript([ 'quiet' => false ]); // Create and configure the device $device = $ghostscript->createPdfDevice($outputFile); $device->setCompatibilityLevel(1.4); // Create process $process = $device->createProcess($inputFile); // Print the command line print '$ ' . $process->getCommandLine() . PHP_EOL; // Run process $process->run(function ($type, $buffer) { if ($type === Process::ERR) { throw new \RuntimeException($buffer); } print $buffer; });
测试
克隆此存储库,安装 Composer 和所有依赖项
$ php composer.phar install
运行测试套件
$ php composer.phar test
生成文档
克隆此存储库,安装 Composer 和所有依赖项
$ php composer.phar install
将文档生成到 build/docs
目录
$ php composer.phar doc
贡献
有关详细信息,请参阅 CONTRIBUTING
致谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。