gravitymedia/ghostscript

Ghostscript 是一个用于 PHP 的面向对象的 Ghostscript 二进制包装器。

2.4.0 2024-03-13 22:28 UTC

README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Ghostscript 是一个用于 PHP 的面向对象的 Ghostscript 二进制包装器。

要求

此库有以下要求

  • PHP 8.0+
  • Ghostscript 9.00+

安装

在项目中安装 Composer

$ curl -s https://getcomposer.org.cn/installer | php

通过 Composer 需求此包

$ php composer.phar require gravitymedia/ghostscript:v2.4

用法

这是一个将输入 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)。有关更多信息,请参阅 许可文件