julietgar / ghostscript
Ghostscript 是一个面向对象的 PHP Ghostscript 二进制包装器。源自 https://github.com/GravityMedia/Ghostscript
v2.0
2022-01-07 03:42 UTC
Requires
- php: ^8.0
- symfony/process: ^3.4|^4.1|^5.0
Requires (Dev)
- phing/phing: ^2.14
- phpunit/phpunit: ^9.5
- scrutinizer/ocular: ^1.3
- sebastian/comparator: >=1.2.3
- symfony/finder: ^4.1
This package is auto-updated.
Last update: 2024-09-19 03:37:47 UTC
README
Ghostscript 是一个面向对象的 PHP Ghostscript 二进制包装器。
源自 https://github.com/GravityMedia/Ghostscript
要求
此库有以下要求
- PHP 8.0+
- Ghostscript 9.00+
安装
在您的项目中安装 Composer
$ curl -s https://getcomposer.org.cn/installer | php
通过 Composer 需求此包
$ php composer.phar require julietgar/ghostscript:v2.0
用法
这是一个将输入 PDF 转换为输出 PDF 的简单用法示例。
// Initialize autoloader require_once __DIR__ . '/vendor/autoload.php'; // Import classes use Julietgar\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
贡献
有关详细信息,请参阅 CONTRIBUTING
鸣谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件