is this the right php header for pdftk

Viewed 204

I'm writing a very basic catenation script and lifted this straight off the pdftk 0.10.0 packagist site:

    use mikehaertl\pdftk\Pdf;


// Extract pages 1-2 into a new file
$pdf = new Pdf('sourcefile.pdf');
$result = $pdf->cat(1, 2)
        ->saveAs('newfile.pdf');
if ($result === false) {
    $error = $pdf->getError();
}

But I'm getting this error:

Fatal error: Uncaught Error: Class "mikehaertl\pdftk\Pdf" not found in C:\PHP8\index.php:7 Stack trace: #0 {main} thrown in C:\PHP8\index.php on line 7

All the sample scripts I've seen have that same header. I'm sure it's something really basic that I'm not seeing here.

3 Answers

Since the error is showing the Class not found, it would make me initially think that the package wasn’t installed in your project. If you run composer require mikehaertl/php-pdftk, does that get you rolling?

If you’re not familiar with Composer, here’s a quick guide to getting started: https://packagist.org/

Apparently, when installed via composer, the pdftk.exe file is not downloaded for some reason. I downloaded it manually from the github page and referred to it in the header.

Ok, finally found the answer. You need to install pdftk beforehand as packagist does not automatically pull it for you.

Related