gravitymedia / ghostscript
Ghostscript is an object oriented Ghostscript binary wrapper for PHP.
Installs: 135 207
Dependents: 0
Suggesters: 0
Security: 0
Stars: 26
Watchers: 2
Forks: 18
Open Issues: 1
Requires
- php: ^8.0
- symfony/process: ^5.0|^6.0|^7.0
Requires (Dev)
- phing/phing: ^2.14
- phpunit/phpunit: ^9.5|^10.0|^11.0
- scrutinizer/ocular: ^1.3
- sebastian/comparator: >=1.2.3
- symfony/finder: ^5.0|^6.0|^7.0
This package is auto-updated.
Last update: 2024-11-06 10:51:11 UTC
README
Ghostscript is an object oriented Ghostscript binary wrapper for PHP.
Requirements
This library has the following requirements:
- PHP 8.0+
- Ghostscript 9.00+
Installation
Install Composer in your project:
$ curl -s https://getcomposer.org/installer | php
Require the package via Composer:
$ php composer.phar require gravitymedia/ghostscript:v2.4
Usage
This is a simple usage example how to convert an input PDF to an output 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; });
Testing
Clone this repository, install Composer and all dependencies:
$ php composer.phar install
Run the test suite:
$ php composer.phar test
Generating documentation
Clone this repository, install Composer and all dependencies:
$ php composer.phar install
Generate the documentation to the build/docs
directory:
$ php composer.phar doc
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.