3

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.

andreithegiant
  • 215
  • 1
  • 10

3 Answers3

0

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/

  • Yes, I use composer a lot and downloaded it using ```composer require mikehaertl/php-pdftk```. I suspected it wasn't installed but running ```composer show -i``` reveals that it is installed. The caveat is, it may not have installed correctly as neither the composer json file on packagist (https://packagist.org/packages/mikehaertl/php-pdftk) or GitHub (https://github.com/mikehaertl/php-pdftk) is working right. So I just copied the dependencies from the composer lock file into the json file. – andreithegiant Mar 15 '21 at 02:44
  • If those two composer.json files don't work, did you file according bug tickets? Be prepared to provide a [mcve] though. Unlike your above question, it should come with full info though, like e.g. steps to do manually, not some PHP code fragments. – Ulrich Eckhardt May 02 '21 at 08:49
0

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.

andreithegiant
  • 215
  • 1
  • 10
0

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

andreithegiant
  • 215
  • 1
  • 10