Skip to content

Commit

Permalink
Fixes "Call to undefined method Smalot\PdfParser\Header::__toString()…
Browse files Browse the repository at this point in the history
…" in Font.php (#393)

* Fix Fatal Error when Encoding is not Encoding

make sure that the header encoding is instance of class Encoding before converting it to string

* added missing test for #384

Co-authored-by: fsmoak <[email protected]>
  • Loading branch information
k00ni and fsmoak authored Feb 25, 2021
1 parent 73204b4 commit b6db6aa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Binary file added samples/bugs/Issue391.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions src/Smalot/PdfParser/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions tests/Integration/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
Expand Down

0 comments on commit b6db6aa

Please sign in to comment.