/** * @param string $inputfile * @param string $toEncoding * * @throws FileNotFoundException * @return string */ 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 testToText() { $pdfFile = new PdfFile($this->createPdfinfoMock(), Pdftotext::create($this->createLoggerMock()), $this->createPdftohtmlMock()); $text = $pdfFile->toText(__DIR__ . '/../files/pdf-sample.pdf'); $this->assertNotEmpty($text); $this->assertEquals($this->createTextContent(), $text); }
public function setUp() { if (!class_exists('Poppler\\Processor\\PdfFile')) { $this->markTestSkipped('Poppler\\Processor\\PdfFile not available.'); } try { $this->reader = new PdfInfoReader(new PdfFile(\Poppler\Driver\Pdfinfo::create(), \Poppler\Driver\Pdftotext::create(), \Poppler\Driver\Pdftohtml::create())); } catch (\Exception $e) { $this->markTestSkipped('PdfInfoReader not available.'); } }
/** * @expectedException \Poppler\Exception\ExecutableNotFoundException */ public function testCreateFailureThrowsAnException() { Pdftotext::create($this->createLoggerMock(), array('pdftotext.binaries' => '/path/to/nowhere')); }