gmi / toolkit-pdftk
PDFtk wrapper
3.3.2
2026-10-14 10:00 UTC
Requires
- php: >=7.1.0
- gmi/toolkit-sorter: ~1.0
- symfony/finder: ~3.0|~4.0|~5.0|~6.0
- symfony/process: ~3.0|~4.0|~5.0|~6.0
Requires (Dev)
- phpunit/phpunit: ^7.5
- symfony/phpunit-bridge: ^4.2|^5.4|^6.4|^7.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This library provides an object-oriented, simple interface for the most important PDFtk features.
The current build status and code analysis can be found here:
Requirements
- PHP 7.1.0 or higher
- mbstring extension
- pdftk or pdfcpu (0.11 to 0.16)
pdfcpu 0.16 and newer refuse to run on a configuration written by an older pdfcpu version: every call
fails with configuration reset required. After upgrading pdfcpu, back up the configuration and run
pdfcpu config reset as the user which executes pdfcpu.
Installation
The recommended way to install toolkit-pdftk is via composer.
"require": { "gmi/toolkit-pdftk": "3.1.*" }
Usage examples
use Gmi\Toolkit\Pdftk\Bookmark; use Gmi\Toolkit\Pdftk\Pdftk; $source = '/path/to/source.pdf'; $target = '/path/to/target.pdf'; $pdftk = new Pdftk(); // import a source PDF (metadata, page information, bookmarks) $pdftk->import($source); // create an additional bookmark $exampleBookmark = new Bookmark(); $exampleBookmark ->setPageNumber(1) ->setLevel(2) ->setTitle('Section 3') ; // add the bookmark to the PDF $pdftk->bookmarks()->add($exampleBookmark); // set metadata entry for the PDF $pdftk->metadata()->set('Author', 'Jane Doe'); // apply bookmarks and metadata to the source PDF using a specified target PDF $pdftk->apply($source, $target);
Tests
The test suite can be run with vendor/bin/phpunit tests.