我想将 pdf 转换为文本。但它给了我错误。为什么 spatie/pdf-to-text 显示错误?

I want to convert pdf to text. but it gives me error. why spatie/pdf-to-text is showing error?

我的代码

<?php 
require_once 'vendor/autoload.php';

use Spatie\PdfToText\Pdf;

echo Pdf::getText('simple.pdf');

错误信息

Fatal error: Uncaught Spatie\PdfToText\Exceptions\CouldNotExtractText: The command ""/usr/bin/pdftotext" simple.pdf -" failed. Exit Code: 1(General error) Working directory: C:\xampp\htdocs\pdf Output: ================ Error Output: ================ The system cannot find the path specified. in C:\xampp\htdocs\pdf\vendor\spatie\pdf-to-text\src\Pdf.php:73 Stack trace: #0 C:\xampp\htdocs\pdf\vendor\spatie\pdf-to-text\src\Pdf.php(84): Spatie\PdfToText\Pdf->text() #1 C:\xampp\htdocs\pdf\index.php(7): Spatie\PdfToText\Pdf::getText('simple.pdf') #2 {main} thrown in C:\xampp\htdocs\pdf\vendor\spatie\pdf-to-text\src\Pdf.php on line 73

pdftext 是一个位于您系统中的 .exe 文件。找到这个文件的路径和
然后像这样放置路径并将其传递给像这样的getText方法

$path = 'c:/Program Files/Git/mingw64/bin/pdftotext';
echo Pdf::getText('simple.pdf', $path);

希望对您有所帮助

Note: $path this should be your path of pdftext.exe file