PHP code example of ministryofjustice / ghostscript

1. Go to this page and download the library: Download ministryofjustice/ghostscript library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ministryofjustice / ghostscript example snippets


$transcoder = Ghostscript\Transcoder::create();

$transcoder = Ghostscript\Transcoder::create(array(
    'timeout' => 42,
    'gs.binaries' => '/opt/local/gs/bin/gs',
), $logger);

$transcoder->toPDF('document.pdf', 'first-page.pdf', 1, 1);

$transcoder->toImage('document.pdf', 'output.jpg');

# 400 is a good quality for jpeg. Default is 200. Default format is 'png16m'
$transcoder->toImage('document.pdf', 'output.jpg', 400, 'jpeg');

$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 () {
        return $app['monolog']; // use Monolog service provider
    }),
));

$app['ghostscript.pdf-transcoder']->toImage('document.pdf', 'image.jpg');