2017-12-08 10 views
0

이 질문은 계속됩니다 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); 
?> 
+0

가 진짜 문제를 가리 키도록 도움말 :'$ 프로세스 레 > isSuccessful()'false를 반환합니다 –

+0

당신은이 경로를 가지고 있습니까 :''/ usr/bin/pdftotext'' (생성자에서) – Justinas

+0

@Justinas 아니오이 경로가 없습니다 .... 저는 제 질문에 프로젝트를 언급했습니다 구조 – Georges

답변

0

나는 pdf 파일 검사에서 얻을 내용이 자식을위한 테스트 프로젝트를 생성

https://github.com/akkapong/test-pdf

pdf-to-text 패키지는 pdftotext 명령이 필요하므로 먼저 설치해야합니다.

설치 한 후 명령은 라인 6

을에 파일 test.php에 경로를 대체 할 수있는 명령 의 경로에 대해 알려 ================합니다 == 실행 test.php ================= $ PHP는 test.php

희망

+0

패키지를 찾을 수있는 곳 ** pdftotext 명령 ** 윈도우 7을 사용하고 있습니까? – Georges

+0

ftp : //ftp.gnome.org/Public/GNOME/binaries/win32/dependencies/ poppler를 찾으십시오. –

+0

@ Akkapong Kajornwongwattana 저는 대답을 이해하지 못했습니다. – Georges