PHP code example of bolongo / phppdfcrop

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

    

bolongo / phppdfcrop example snippets


// You can pass a filename or an options array to the constructor
$pdfCrop = new PdfCrop('/path/to/document.pdf');
if($pdfCrop->getError() != null) {
    //Handle error here
}

//Default values
$options = [
    'verbose' => false,//bool
    'debug' => false,//bool
    'gscmd' => 'gs',//string
    'tex-extension' => 'pdftex',//string
    'pdftexcmd' =>'pdftex',//string
    'xetexcmd' => 'xetex',//string
    'luatexcmd' => 'luatex',//string
    'margins' => [0, 0, 0, 0],//array|string
    'clip' => false,//bool
    'hires' => false,//bool
    'ini' => false,//bool

    'restricted' => false,//bool
    'papersize' => null,//string
    'resolution' => null,//string|int
    'bbox' => null,//string|array
    'bbox-odd' => null,//string|array
    'bbox-even' => null,//string|array
    'pdfversion' => null,//string
    
    'original' => null,//string
];

$pdfCrop = new PDFCrop($options);
$pdfCrop->setOptions($options);

$pdfCrop = new PDFCrop('/path/to/document.pdf');
$pdfCrop->original = '/path/to/document.pdf';

//Default values
$commandOptions = [
    'binary' => 'pdfcrop',//string
    'tmpDir' => null,//string
    'ignoreWarnings' => true,//bool
    'ignoreOptionValidationErrors' => true,//bool
];
$pdfCrop = new PDFCrop($commandOptions);
$pdfCrop->setOptions($commandOptions);
$pdfCrop->binary = '/path/to/pdfcrop';
$pdfCrop->tmpDir = '/path/to/tmpDir';
$pdfCrop->ignoreWarnings = true;
$pdfCrop->ignoreOptionValidationErrors = true;

$options = [
    'ignoreOptionValidationErrors' => false,
    'tex-extension' => 'im wrong',
];
try {
    $pdfCrop = new PDFCrop($options);
    $pdfCrop->setOptions($options);
} catch(Exception $e) {
    //The detailed error message will be present in the getMessage() method
    $e->getMessage();
}

$options = [
    'original' => '/path/to/original.pdf',
    'ignoreWarnings' => false,
];
$pdfCrop = new PDFCrop($options);
try {
    $pdfCrop->saveAs('/path/to/cropped.pdf');
    $croppedPdfContents = $pdfCrop->toString();
} catch(Exception $e) {
    //The detailed error message will be present in the getMessage() method
    $e->getMessage();
}

$options = [
    'original' => '/path/to/original.pdf',
];
$pdfCrop = new PDFCrop($options);
$croppedPdfContents = $pdfCrop->toString();
if($pdfCrop->getError() != null) {
    //Handle error
}
$pdfCrop->saveAs('/path/to/cropped.pdf');
if($pdfCrop->getError() != null) {
    //Handle error
}