phplaravelpdftotext

Class 'Spatie\PdfToText\Pdf' not found


I tried to keep running Spatie\PdfToText. I have the following error:

Class 'Spatie\PdfToText\Pdf' not found

I read this but it doesn't help.

use Spatie\PdfToText\Pdf;

public function importInRequestStore($projectId, Request $request)
{
    require  base_path().'/vendor/autoload.php';
    $text = (new Pdf())
        ->setPdf('book.pdf')
        ->text();
}

What is wrong in this code? I do not find a solution with google.Thanks in advance.

enter image description here


Solution

  • It will not load the class since these spatie classes have no service providers.

    You should modify the composer.json which under the root of your Laravel/Lumen project.

    You can add a classmap path like below in the autoload node:

    "autoload": {
        "classmap": [
            "vendor/spatie"
        ]
    },
    

    Or you can add a psr-4 key-value like below in the autoload node (this is the way recommanded):

    "autoload": {
        "psr-4": [
            "Spatie\\": "vendor/spatie"
        ]
    },
    

    And the last IMPORTANT thing is you should composer dump-autoload then. Otherwise the spatie class never load in.