PHPackages                             bolongo/phppdfcrop - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. bolongo/phppdfcrop

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

bolongo/phppdfcrop
==================

PHP wrapper around pdfcrop

v1.0.1(5y ago)02.0k↓18.8%MITPHPPHP &gt;=5.6.0CI failing

Since Jul 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/bolongo/phppdfcrop)[ Packagist](https://packagist.org/packages/bolongo/phppdfcrop)[ RSS](/packages/bolongo-phppdfcrop/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (4)Used By (0)

PHP PDFcrop
===========

[](#php-pdfcrop)

[![Build Status](https://camo.githubusercontent.com/f9813355bd458404c9f9d2c124641a6c1523922f0afcd3184d31b68cd95f7a77/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f626f6c6f6e676f2f70687070646663726f702e706e67)](http://travis-ci.org/bolongo/phppdfcrop)[![Latest Stable Version](https://camo.githubusercontent.com/2d82a32a40827808fef21e79d1798eda55dcd89ac6576a2c1dd241080a3ac1d9/68747470733a2f2f706f7365722e707567782e6f72672f626f6c6f6e676f2f70687070646663726f702f762f737461626c652e737667)](https://packagist.org/packages/bolongo/phppdfcrop)[![Total Downloads](https://camo.githubusercontent.com/9d37adbee9d826ef1aba4b0368c519d9cb0b10bd14e86494322659f95febe219/68747470733a2f2f706f7365722e707567782e6f72672f626f6c6f6e676f2f70687070646663726f702f646f776e6c6f616473)](https://packagist.org/packages/bolongo/phppdfcrop)[![License](https://camo.githubusercontent.com/1e110cca9ac15fd5c31d2b5ff29fc5f4b1d3acac2b42ffc877d3e244d3100590/68747470733a2f2f706f7365722e707567782e6f72672f626f6c6f6e676f2f70687070646663726f702f6c6963656e73652e737667)](https://packagist.org/packages/bolongo/phppdfcrop)

PHP PDFcrop is a PHP wrapper for [pdfcrop](http://pdfcrop.sourceforge.net/) based on [PHP WkhtmlToPdf](https://github.com/mikehaertl/phpwkhtmltopdf) by [Michael Härtl](https://github.com/mikehaertl). **The `pdfcrop` command must be installed in the system.**

Installation
------------

[](#installation)

Install the package through [composer](https://getcomposer.org/):

```
composer require bolongo/phppdfcrop

```

Make sure you include the composer [autoloader](https://getcomposer.org/doc/01-basic-usage.md#autoloading)somewhere in your codebase.

Example
-------

[](#example)

```
// 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
}
```

Options
-------

[](#options)

### Command options

[](#command-options)

These are used as options for the `pdfcrop` shell command. For a better explanation of these options, please see `pdfcrop --help`.

```
//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
];
```

**Description**

- **verbose:** Makes the command do a verbose printing.
- **debug:** Makes the command print debug information.
- **gscmd:** Specifies the path to the ghostscript command to be used by the command.
- **tex-extension:** Specifies the tex extension to be used by the command. Value must be `pdftex`, `xetex` or `luatex`. This option is the union of `--pdftex`, `--xetex` and `--luatex` options present in the `pdfcrop` shell command, in which only one of these must be specified.
- **pdftexcmd:** Specifies the path to the pdftex command to be used by the command.
- **xetexcmd:** Specifies the path to the xetex command to be used by the command.
- **luatexcmd:** Specifies the path to the luatex command to be used by the command.
- **margins:** Specifies extra margins to the command, unit is bp. If only one number is given, then it is used for all margins, in the case of two numbers they are used for right and bottom.
- **clip:** Specifies clip support to the command if margins are set.
- **hires:** Specifies the use of `%%HiResBoundingBox` instead of `%%BoundingBox`.
- **ini:** Specifies the use of iniTeX variant of the TeX compiler to the command.
- **original:** File to be cropped by the command.

**How to set options to a PDFCrop instance:**

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

The **original** option is special, as it can be specified as a member of the array set on the constructor or the `setOptions($options)` method, as a replacement of the array set on the constructor or directly on the attribute `original`.

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

### Wrapper options

[](#wrapper-options)

These options are specific to the wrapper. These options can be passed to the wrapper in the constructor or via the `setOptions($options)` method, mixed with the **Command Options**.

```
//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;
```

**Description**

- **binary:** path to the `pdfcrop` command.
- **tmpDir:** path to the tmp directory. Defaults to the PHP temp dir.
- **ignoreWarnings:** prevents the process from throwing exceptions.
- **ignoreOptionValidationErrors:** prevents the option validation from throwing exceptions (malformed options will be ignored).

Error Handling
--------------

[](#error-handling)

`new PDFCrop($options)` and `setOptions($options)` will throw exceptions if an option is malformed and the option `ignoreOptionValidationErrors` is set to `false`.

```
$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();
}
```

`new saveAs($options)` and `toString()` will throw exceptions if an error presents itself in the command or the saving of the generated file if `ignoreWarnings` is set to `false`.

```
$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();
}
```

`saveAs($options)` and `toString()` with the option `ignoreWarnings` set to `true` will prevent exceptions from showing, but if an error presents itself in the process or saving of the generated file, the method `getError()`will return a string with the detailed error message.

```
$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
}
```

Changelog
---------

[](#changelog)

Check this library's changelog in [here](CHANGELOG.md).

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

3

Last Release

2180d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3e232e78b2dd0a14739a010f5a5dcd8580b66b5067e24b46a12c471824701432?d=identicon)[bolongo](/maintainers/bolongo)

---

Top Contributors

[![bolongo](https://avatars.githubusercontent.com/u/8070418?v=4)](https://github.com/bolongo "bolongo (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bolongo-phppdfcrop/health.svg)

```
[![Health](https://phpackages.com/badges/bolongo-phppdfcrop/health.svg)](https://phpackages.com/packages/bolongo-phppdfcrop)
```

###  Alternatives

[mikehaertl/php-pdftk

A PDF conversion and form utility based on pdftk.

1.0k12.1M14](/packages/mikehaertl-php-pdftk)[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[mikehaertl/phpwkhtmltopdf

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface

1.6k21.5M46](/packages/mikehaertl-phpwkhtmltopdf)[codemix/yii2-excelexport

A utility to quickly create Excel files from query results or raw data

105391.8k](/packages/codemix-yii2-excelexport)[daandesmedt/phpheadlesschrome

A PHP wrapper for using Google Chrome Headless mode. Convert URL or HTML to a PDF / screenshot. Easy to use and OOP interfaced.

92255.6k](/packages/daandesmedt-phpheadlesschrome)[spacecatninja/imager-x

Ninja powered image transforms.

29405.1k38](/packages/spacecatninja-imager-x)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
