이 질문은 계속됩니다 last question with different error PDF 파일을 선택하고 텍스트 파일로 변환하는 PHP 코드가 있습니다.PHP 코드가 표시하는 오류를 수정하는 방법은 무엇입니까?
나는 외부 라이브러리 을 작곡가와 함께 사용하여 PDF 파일로 - 텍스트을 사용하고 있습니다. 다음
는시스템 디스플레이 오류입니다 :
Fatal error: Uncaught Spatie\PdfToText\Exceptions\CouldNotExtractText: The command "/usr/bin/pdftotext "pdf.pdf" -" failed. Exit Code: 1(General error) Working directory: C:\xampp\htdocs\testcomposer Output: ================ Error Output: ================ The system cannot find the path specified. in C:\xampp\htdocs\testcomposer\src\Pdf.php:37 Stack trace: #0 C:\xampp\htdocs\testcomposer\test2.php(8): Spatie\PdfToText\Pdf->text() #1 {main} thrown in C:\xampp\htdocs\testcomposer\src\Pdf.php on line 37
프로젝트 구조 :
testcomposer
SRC
-Exceptions -CouldNotExtractText.php -PdfNotFound.php -pdf.php
,691,363,210
벤더
-composer -autoload.php
composer.json
test2.php
pdf.php
코드
pdf.php
<?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();
}
}
composer.json
{
"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": "[email protected]",
"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"
}
}
test2.php는
<?php
require 'vendor/autoload.php';
use Spatie\PdfToText\Pdf;
$text = (new Pdf())
->setPdf('pdf.pdf')
->text();
print_r($text);
?>
가 진짜 문제를 가리 키도록 도움말 :'$ 프로세스 레 > isSuccessful()'false를 반환합니다 –
당신은이 경로를 가지고 있습니까 :''/ usr/bin/pdftotext'' (생성자에서) – Justinas
@Justinas 아니오이 경로가 없습니다 .... 저는 제 질문에 프로젝트를 언급했습니다 구조 – Georges