PHP Poppler实现失败

PHP Poppler实现失败,php,poppler,Php,Poppler,除了Poppler之外,我目前正在使用此库,以便将PDF文件转换为HTML。我通过composer安装了库,不幸的是,除了一些关于安装的指南外,没有其他文档,但仍然不完整 鉴于此主要API用法: $file = new Poppler\Process\PdfFile(...); // Get pdf info print_r($file->getInfo('test.pdf')); // Get text content of pdf echo $file->toText('te

除了
Poppler
之外,我目前正在使用此库,以便将
PDF
文件转换为
HTML
。我通过
composer
安装了库,不幸的是,除了一些关于安装的指南外,没有其他文档,但仍然不完整

鉴于此
主要API用法

$file = new Poppler\Process\PdfFile(...);

// Get pdf info
print_r($file->getInfo('test.pdf'));

// Get text content of pdf
echo $file->toText('test.pdf');

// Transform to html
$file->toHtml('test.pdf', '/path/for/html');
<?php 
include 'vendor/autoload.php';
use Poppler\Processor\PdfFile;

use Poppler\Driver\Pdfinfo;
use Poppler\Driver\Pdftohtml;
use Poppler\Driver\Pdftotext;

$a = new Pdfinfo;
$b = new Pdftohtml;
$c = new Pdftotext;

$file = new PdfFile($a,$b,$c);

print_r($file->getInfo('test.pdf'));
echo $file->toText('test.pdf');

$file->toHtml('test.pdf', 'Results');

?>
Catchable fatal error: Argument 1 passed to Alchemy\BinaryDriver\AbstractBinary::__construct() must be an instance of Alchemy\BinaryDriver\ProcessBuilderFactoryInterface, none given
<?php

namespace Poppler\Processor;

use Poppler\Driver\Pdfinfo;
use Poppler\Driver\Pdftohtml;
use Poppler\Driver\Pdftotext;
use Poppler\Exception\FileNotFoundException;

class PdfFile
{

    private $pdfinfo;
    private $pdftotext;
    private $pdftohtml;

    public function __construct(Pdfinfo $pdfinfo, Pdftotext $pdftotext, Pdftohtml $pdftohtml)
    {
     $this->pdfinfo = $pdfinfo;
     $this->pdftotext = $pdftotext;
     $this->pdftohtml = $pdftohtml;
    }

    public function toText($inputfile, $toEncoding = 'UTF-8')
    {
        if (!file_exists($inputfile)) {
            throw new FileNotFoundException("File $inputfile not found.");
        }

        $output = $this->pdftotext->command(array('-nopgbrk', $inputfile, '-'));
        $fromEncoding = mb_detect_encoding($output);
        if ($fromEncoding) {
            return mb_convert_encoding($output, $toEncoding, $fromEncoding);
        }

        return mb_convert_encoding($output, $toEncoding);
    }

    public function toHtml($inputfile, $outputfile)
    {
        if (!file_exists($inputfile)) {
            throw new FileNotFoundException("File $inputfile not found.");
        }

        $output = $this->pdftohtml->command(array($inputfile, $outputfile));

        return $output;
    }


    public function getInfo($inputfile)
    {
        if (!file_exists($inputfile)) {
            throw new FileNotFoundException("File $inputfile not found.");
        }

        $args = array($inputfile);

        $output = $this->pdfinfo->command($args);

        $info = array();
        foreach (explode(PHP_EOL, $output) as $line) {
            if (strpos($line, ': ') === false) {
                continue;
            }
            $parts = explode(': ', $line);
            $key = trim($parts[0]);
            $value = trim($parts[1]);
            $info[$key] = $value;
        }

        return $info;
    }
}
我甚至不能定义在
$file=new Poppler\Process\PdfFile(…)中应该给出哪些参数

我尝试过的:

$file = new Poppler\Process\PdfFile(...);

// Get pdf info
print_r($file->getInfo('test.pdf'));

// Get text content of pdf
echo $file->toText('test.pdf');

// Transform to html
$file->toHtml('test.pdf', '/path/for/html');
<?php 
include 'vendor/autoload.php';
use Poppler\Processor\PdfFile;

use Poppler\Driver\Pdfinfo;
use Poppler\Driver\Pdftohtml;
use Poppler\Driver\Pdftotext;

$a = new Pdfinfo;
$b = new Pdftohtml;
$c = new Pdftotext;

$file = new PdfFile($a,$b,$c);

print_r($file->getInfo('test.pdf'));
echo $file->toText('test.pdf');

$file->toHtml('test.pdf', 'Results');

?>
Catchable fatal error: Argument 1 passed to Alchemy\BinaryDriver\AbstractBinary::__construct() must be an instance of Alchemy\BinaryDriver\ProcessBuilderFactoryInterface, none given
<?php

namespace Poppler\Processor;

use Poppler\Driver\Pdfinfo;
use Poppler\Driver\Pdftohtml;
use Poppler\Driver\Pdftotext;
use Poppler\Exception\FileNotFoundException;

class PdfFile
{

    private $pdfinfo;
    private $pdftotext;
    private $pdftohtml;

    public function __construct(Pdfinfo $pdfinfo, Pdftotext $pdftotext, Pdftohtml $pdftohtml)
    {
     $this->pdfinfo = $pdfinfo;
     $this->pdftotext = $pdftotext;
     $this->pdftohtml = $pdftohtml;
    }

    public function toText($inputfile, $toEncoding = 'UTF-8')
    {
        if (!file_exists($inputfile)) {
            throw new FileNotFoundException("File $inputfile not found.");
        }

        $output = $this->pdftotext->command(array('-nopgbrk', $inputfile, '-'));
        $fromEncoding = mb_detect_encoding($output);
        if ($fromEncoding) {
            return mb_convert_encoding($output, $toEncoding, $fromEncoding);
        }

        return mb_convert_encoding($output, $toEncoding);
    }

    public function toHtml($inputfile, $outputfile)
    {
        if (!file_exists($inputfile)) {
            throw new FileNotFoundException("File $inputfile not found.");
        }

        $output = $this->pdftohtml->command(array($inputfile, $outputfile));

        return $output;
    }


    public function getInfo($inputfile)
    {
        if (!file_exists($inputfile)) {
            throw new FileNotFoundException("File $inputfile not found.");
        }

        $args = array($inputfile);

        $output = $this->pdfinfo->command($args);

        $info = array();
        foreach (explode(PHP_EOL, $output) as $line) {
            if (strpos($line, ': ') === false) {
                continue;
            }
            $parts = explode(': ', $line);
            $key = trim($parts[0]);
            $value = trim($parts[1]);
            $info[$key] = $value;
        }

        return $info;
    }
}
这里是PdfFile.php:

$file = new Poppler\Process\PdfFile(...);

// Get pdf info
print_r($file->getInfo('test.pdf'));

// Get text content of pdf
echo $file->toText('test.pdf');

// Transform to html
$file->toHtml('test.pdf', '/path/for/html');
<?php 
include 'vendor/autoload.php';
use Poppler\Processor\PdfFile;

use Poppler\Driver\Pdfinfo;
use Poppler\Driver\Pdftohtml;
use Poppler\Driver\Pdftotext;

$a = new Pdfinfo;
$b = new Pdftohtml;
$c = new Pdftotext;

$file = new PdfFile($a,$b,$c);

print_r($file->getInfo('test.pdf'));
echo $file->toText('test.pdf');

$file->toHtml('test.pdf', 'Results');

?>
Catchable fatal error: Argument 1 passed to Alchemy\BinaryDriver\AbstractBinary::__construct() must be an instance of Alchemy\BinaryDriver\ProcessBuilderFactoryInterface, none given
<?php

namespace Poppler\Processor;

use Poppler\Driver\Pdfinfo;
use Poppler\Driver\Pdftohtml;
use Poppler\Driver\Pdftotext;
use Poppler\Exception\FileNotFoundException;

class PdfFile
{

    private $pdfinfo;
    private $pdftotext;
    private $pdftohtml;

    public function __construct(Pdfinfo $pdfinfo, Pdftotext $pdftotext, Pdftohtml $pdftohtml)
    {
     $this->pdfinfo = $pdfinfo;
     $this->pdftotext = $pdftotext;
     $this->pdftohtml = $pdftohtml;
    }

    public function toText($inputfile, $toEncoding = 'UTF-8')
    {
        if (!file_exists($inputfile)) {
            throw new FileNotFoundException("File $inputfile not found.");
        }

        $output = $this->pdftotext->command(array('-nopgbrk', $inputfile, '-'));
        $fromEncoding = mb_detect_encoding($output);
        if ($fromEncoding) {
            return mb_convert_encoding($output, $toEncoding, $fromEncoding);
        }

        return mb_convert_encoding($output, $toEncoding);
    }

    public function toHtml($inputfile, $outputfile)
    {
        if (!file_exists($inputfile)) {
            throw new FileNotFoundException("File $inputfile not found.");
        }

        $output = $this->pdftohtml->command(array($inputfile, $outputfile));

        return $output;
    }


    public function getInfo($inputfile)
    {
        if (!file_exists($inputfile)) {
            throw new FileNotFoundException("File $inputfile not found.");
        }

        $args = array($inputfile);

        $output = $this->pdfinfo->command($args);

        $info = array();
        foreach (explode(PHP_EOL, $output) as $line) {
            if (strpos($line, ': ') === false) {
                continue;
            }
            $parts = explode(': ', $line);
            $key = trim($parts[0]);
            $value = trim($parts[1]);
            $info[$key] = $value;
        }

        return $info;
    }
}