diff --git a/samples/bugs/Issue391.pdf b/samples/bugs/Issue391.pdf new file mode 100644 index 00000000..3294f13a Binary files /dev/null and b/samples/bugs/Issue391.pdf differ diff --git a/src/Smalot/PdfParser/Font.php b/src/Smalot/PdfParser/Font.php index 0be46d78..deb2d6ce 100644 --- a/src/Smalot/PdfParser/Font.php +++ b/src/Smalot/PdfParser/Font.php @@ -106,6 +106,7 @@ public function translateChar($char, $use_default = true) if ( \strlen($char) < 2 && $this->has('Encoding') + && $this->get('Encoding') instanceof Encoding && WinAnsiEncoding::class === $this->get('Encoding')->__toString() ) { $fallbackDecoded = self::uchr($dec); diff --git a/tests/Integration/ParserTest.php b/tests/Integration/ParserTest.php index 4b217219..dee42d27 100644 --- a/tests/Integration/ParserTest.php +++ b/tests/Integration/ParserTest.php @@ -238,6 +238,31 @@ public function testIssue359() // $this->assertStringContainsString('sprawie swobodnego przepływu takich danych oraz uchylenia dyrektywy', $document->getText()); } + /** + * Tests if PDF triggers "Call to undefined method Smalot\PdfParser\Header::__toString()". + * + * It happened because there was a check missing in Font.php (~ line 109). + * + * @see https://github.com/smalot/pdfparser/issues/391 + */ + public function testIssue391() + { + /** + * PDF provided by @dhildreth for usage in our test environment. + * + * @see https://github.com/smalot/pdfparser/issues/391#issuecomment-783504599 + */ + $filename = $this->rootDir.'/samples/bugs/Issue391.pdf'; + + $document = $this->fixture->parseFile($filename); + + // check for an example string (PDF consists of many pages) + $this->assertStringContainsString( + '(This Code will be changed while mass production)', + $document->getText() + ); + } + /** * Tests behavior when changing default font space limit (-50). *