2017 © Pedro Peláez
 

library phpgs

PHP Wrapper for Ghost Script

image

webit/phpgs

PHP Wrapper for Ghost Script

  • Wednesday, November 1, 2017
  • by dbojdo
  • Repository
  • 1 Watchers
  • 0 Stars
  • 84 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 236 % Grown

The README.md

PHPgs

This package provides PHP Wrapper for GhostScript. It also provides a simple tool for PDF pages splitting / merging., (*1)

Installation

composer require webit/phpgs=^1.0

Usage

Executor

For general purpose use Executor as a generic wrapper for the Ghost Script, (*2)

use Webit\PHPgs\ExecutorBuilder;
use Webit\PHPgs\Input;
use Webit\PHPgs\Output;
use Webit\PHPgs\Options\Options;
use Webit\PHPgs\Options\Device;

/** @var \Webit\PHPgs\Executor $executor */
$executor = ExecutorBuilder::create()->setGhostScriptBinary('/path/to/the/binary/of/gs')->build();

$input = Input::singleFile('/path/to/your/input_file');
$output = Output::create('/path/to/your/tempdir/output.pdf');

// Please note Options class is immutable (every change creates a new instance)
$options = Options::create(Device::pdfWrite())
            // set predefined options (see Options class for all predefined options)
            ->withNoTransparency()
            ->useCropBox()
            ->useCIEColor()
            // change any option you need
            ->withOption('-dWhatever', 'value of whatever');

$executor->execute($input, $output, $options);

PdfManipulator

PdfManipulator provides simplified interface for PDF splitting / merging, (*3)

Merging

use Webit\PHPgs\Pdf\PdfManipulator;

$pdfManipulator = new PdfManipulator($executor);

$input = Input::multipleFiles(
    array(
        'one.pdf',
        'two.pdf',
        'three.pdf'
    )
);

$output = Output::create('/temp-dir/random-5322/output.pdf');

$customOptions = Options::create(); // optional

$pdfManipulator->merge($input, $output, $customOptions);

Splitting pages

use Webit\PHPgs\Pdf\PdfManipulator;

$pdfManipulator = new PdfManipulator($executor);

$input = Input::singleFile('multipage.pdf');

// multi page output
$output = Output::create('/temp-dir/random-12322/output-%d.pdf');

// single page output
// $output = Output::create('/temp-dir/random-12322/output.pdf');

$customOptions = Options::create(); // optional

// splitting pages from 5 to 10
$pdfManipulator->split($input, $output, 5, 10, $customOptions);
// produces output-5.pdf, output-6.pdf, ...

// splitting pages from 5 to the last page
$pdfManipulator->split($input, $output, 5, null, $customOptions);
// produces output-5.pdf, output-6.pdf, ...

// splitting pages from 1 to 10
$pdfManipulator->split($input, $output, null, 10, $customOptions);
// produces output-1.pdf, output-2.pdf, ..., output-10.pdf

Note: To make sure multi-page splitting will work properly, an output always must refer to an empty directory., (*4)

Tests

docker-compose run --rm php5 ./vendor/bin/phpunit

The Versions

01/11 2017

dev-master

9999999-dev

PHP Wrapper for Ghost Script

  Sources   Download

MIT

The Requires

 

The Development Requires

ghostscript ghost script gs pdf merge pdf split

01/11 2017

1.0.0

1.0.0.0

PHP Wrapper for Ghost Script

  Sources   Download

MIT

The Requires

 

The Development Requires

ghostscript ghost script gs pdf merge pdf split