PHP code example of alchemy / ghostscript

1. Go to this page and download the library: Download alchemy/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/ */

    

alchemy / 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');

$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');