From d5dd7a0e3797e1376665151bc055e2e835130c89 Mon Sep 17 00:00:00 2001 From: Alexander Obuhovich Date: Thu, 15 Jan 2015 21:08:34 +0200 Subject: [PATCH] Handle circular references in xObjects --- src/Smalot/PdfParser/Object.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Smalot/PdfParser/Object.php b/src/Smalot/PdfParser/Object.php index ceab589c..5c54cbc3 100644 --- a/src/Smalot/PdfParser/Object.php +++ b/src/Smalot/PdfParser/Object.php @@ -244,6 +244,7 @@ public function getText(Page $page = null) $current_font = new Font($this->document); $current_position_td = array('x' => false, 'y' => false); $current_position_tm = array('x' => false, 'y' => false); + $object_hash = spl_object_hash($this); foreach ($sections as $section) { @@ -351,9 +352,12 @@ public function getText(Page $page = null) case 'Do': if (!is_null($page)) { - $args = preg_split('/\s/s', $command[self::COMMAND]); - $id = trim(array_pop($args), '/ '); - if ($xobject = $page->getXObject($id)) { + $args = preg_split('/\s/s', $command[self::COMMAND]); + $id = trim(array_pop($args), '/ '); + $xobject = $page->getXObject($id); + + if ( is_object($xobject) && $object_hash !== spl_object_hash($xobject) ) { + // Not a circular reference. $text .= $xobject->getText($page); } }