diff --git a/src/Smalot/PdfParser/PDFObject.php b/src/Smalot/PdfParser/PDFObject.php index 7dd36d5a..2bce9ce6 100644 --- a/src/Smalot/PdfParser/PDFObject.php +++ b/src/Smalot/PdfParser/PDFObject.php @@ -222,7 +222,10 @@ private function getDefaultFont(Page $page = null): Font $fonts = $page->getFonts(); } - $fonts[] = $this->document->getFirstFont(); + $firstFont = $this->document->getFirstFont(); + if (null !== $firstFont) { + $fonts[] = $firstFont; + } if (\count($fonts) > 0) { return reset($fonts); diff --git a/tests/Unit/PDFObjectTest.php b/tests/Unit/PDFObjectTest.php new file mode 100644 index 00000000..593f3ec9 --- /dev/null +++ b/tests/Unit/PDFObjectTest.php @@ -0,0 +1,25 @@ +getText()); + } + + public function testGetTextOnPageWithoutContent(): void + { + $document = new Document(); + + static::assertSame(' ', (new PDFObject($document, null, null))->getText(new Page($document))); + } +}