PDF 파일을 텍스트 파일로 변환하는 PHP 코드가 있습니다.이 작업에서는 PDF 라이브러리를 사용할 수 있도록 작성기를 사용하여 외부 라이브러리를 설치했습니다.이 PHP 코드의 오류는 어디에 있습니까?
문제는 설치 한 라이브러리가 필요한데도 시스템이 여전히 PDF 클래스을 인식하지 못한다는 것입니다.
라이브러리의 경로 :
C : \ XAMPP \ htdocs를 \ 업체 \의 spatie의 \ PDF - 투 - 텍스트 \ SRC \ pdf.php
오류 :
Fatal error: Uncaught Error: Class 'Pdf' not found in C:\xampp\htdocs\testwebsite\OSWebProject\test2.php:5 Stack trace: #0 {main} thrown in C:\xampp\htdocs\testwebsite\OSWebProject\test2.php on line 5
코드 : PDF 클래스
<?php
namespace Spatie\PdfToText;
use Spatie\PdfToText\Exceptions\CouldNotExtractText;
use Spatie\PdfToText\Exceptions\PdfNotFound;
use Symfony\Component\Process\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();
}
}
코드 :
당<?php
require_once('C:\xampp\htdocs\vendor\spatie\pdf-to-text\src\pdf.php');
$text = (new Pdf())
->setPdf('اجواء.pdf')
->text();
?>
'pdf.php'에'class Pdf'가 있습니까? 그것은 네임 스페이스인가? – AbraCadaver
처음으로 답변을 얻지 못했기 때문에 새로운 질문을 게시하지 마십시오 –
[PHP에 외부 라이브러리를 포함하는 방법?] (https://stackoverflow.com/questions/47639615/how-to) -includes-external-libraries-on-php) –