我有一个PHP代码,用于选择PDF文件并将其转换为文本文件。
我正在使用外部库 pdf-to-text 和作曲家。
以下是系统显示错误:
致命错误:未捕获错误:未找到类'Pdf' C:\ xampp \ htdocs \ testcomposer \ test2.php:6堆栈跟踪:#0 {main}抛出 在第6行的C:\ xampp \ htdocs \ testcomposer \ test2.php
testcomposer
应用
-Spatie
-pdftotext
-src
-Exceptions
-CouldNotExtractText.php
-PdfNotFound.php
-pdf.php
-symfony
供应商
-composer
-autoload.php
test2.php
xxx.pdf
<?php
namespace Spatie\pdftotext\src;
use Spatie\pdftotext\src\Exceptions;
use Symfony\process;
class Pdf
{
protected $pdf;
protected $binPath;
public function __construct(string $binPath = null)
{
$this->binPath = $binPath ?? '/usr/bin/pdftotext';
}
public function setPdf(string $pdf) : Pdf
{
if (!file_exists($pdf)) {
throw new PdfNotFound("could not find pdf {$pdf}");
}
$this->pdf = $pdf;
return $this;
}
public function text() : string
{
$process = new Process("{$this->binPath} " . escapeshellarg($this->pdf) . " -");
$process->run();
if (!$process->isSuccessful()) {
throw new CouldNotExtractText($process);
}
return trim($process->getOutput(), " \t\n\r\0\x0B\x0C");
}
public static function getText(string $pdf, string $binPath = null) : string
{
return (new static($binPath))
->setPdf($pdf)
->text();
}
}
{
"name": "spatie/pdf-to-text",
"description": "Extract text from a pdf",
"keywords": [
"spatie",
"pdftotext"
],
"homepage": "https://github.com/spatie/pdf-to-text",
"license": "MIT",
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"require": {
"php" : "^7.0",
"symfony/process": "^3.0"
},
"require-dev": {
"phpunit/phpunit" : "^6.4"
},
"autoload": {
"psr-4": {
"src\\": "app/Spatie/pdftotext/src"
}
},
"autoload-dev": {
"psr-4": {
"Spatie\\pdftotext\\Test\\": "tests"
}
},
"scripts": {
"test": "phpunit"
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
use Spatie\pdftotext\src;
$text = (new Pdf())
->setPdf('اجواء.pdf')
->text();
?>