Laravel with spatie / pdf-to-text'找不到pdf book.pdf'

I'm trying to use package spatie/pdf-to-text to convert pdf to text in my laravel project. Pdf located in public path: pdf/book.pdf But I always get this error:

Spatie \ PdfToText \ Exceptions \ PdfNotFound could not find pdf book.pdf

$text = (new Pdf(public_path('pdf')))->setPdf('book.pdf')->text();

return $text;

What do I'm doing wrong?

Input proper directory of your file to argument of setPdf. It should be

public_path('pdf/file/book.pdf')

You are placing it in wrong method. setPdf() method obviously has nothing to do with the constructor argument.