I have PHP code that convert PDF files to text files.For this task I installed an external library using the composer in order to be able to use the library of the PDF.
The problem is that even when I required the installed library the system still not recognize the PDF Class.
The path of the library :
C:xampphtdocsvendorspatiepdf-to-textsrcpdf.php
Error:
Fatal error: Uncaught Error: Class 'Pdf' not found in C:xampphtdocs estwebsiteOSWebProject est2.php:5 Stack trace: #0 {main} thrown in C:xampphtdocs estwebsiteOSWebProject est2.php on line 5
code : pdf class
<?php
namespace SpatiePdfToText;
use SpatiePdfToTextExceptionsCouldNotExtractText;
use SpatiePdfToTextExceptionsPdfNotFound;
use SymfonyComponentProcessProcess;
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(), "
x0Bx0C");
}
public static function getText(string $pdf, string $binPath = null) : string
{
return (new static($binPath))
->setPdf($pdf)
->text();
}
}
code:
<?php
require_once('C:xampphtdocsvendorspatiepdf-to-textsrcpdf.php');
$text = (new Pdf())
->setPdf('?????.pdf')
->text();
?>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…