alchemy / ghostscript
Ghostscript PDF,一个通过ghostscript处理PDF的库
4.1.0
2018-05-02 10:42 UTC
Requires
- php: ~7.0
- alchemy/binary-driver: ~4.1
Requires (Dev)
- phpunit/phpunit: ~6.0
- sami/sami: ~3.0
- silex/silex: ~2.0
This package is auto-updated.
Last update: 2024-09-15 02:22:02 UTC
README
API使用
要实例化Ghostscript驱动程序,最简单的方法是
$transcoder = Ghostscript\Transcoder::create();
您可以通过传递 Psr\Log\LoggerInterface
或配置选项来自定义您的驱动程序。
可用选项包括
gs.binaries
:到ghostscript二进制的路径(或可能的路径数组)。timeout
:底层进程的超时时间。
$transcoder = Ghostscript\Transcoder::create(array( 'timeout' => 42, 'gs.binaries' => '/opt/local/gs/bin/gs', ), $logger);
要将文件处理为PDF格式,请使用toPDF
方法
第三个和第四个参数分别是转换的第一页和页数。
$transcoder->toPDF('document.pdf', 'first-page.pdf', 1, 1);
要将文件渲染为图像,请使用toImage
方法
$transcoder->toImage('document.pdf', 'output.jpg');
Silex服务提供者
一个可用的Silex服务提供者,所有参数都是可选的
$app = new Silex\Application(); $app->register(new Ghostscript\GhostscriptServiceProvider(), array( 'ghostscript.configuration' => array( 'gs.binaries' => '/usr/bin/gs', 'timeout' => 42, ), 'ghostscript.logger' => $app->share(function () use ($app) { return $app['monolog']; // use Monolog service provider }), )); $app['ghostscript.transcoder']->toImage('document.pdf', 'image.jpg');
许可证
在MIT许可证下发布