PHP code example of gmi / toolkit-pdftk

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

    

gmi / toolkit-pdftk example snippets


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