Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/Smalot/PdfParser/PDFObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -788,16 +788,26 @@ public function getTextArray(?Page $page = null): array
break;
}

// If the PDFObject is an Image or a Form, do nothing as
// neither of these XObject types are text.
if ($xobject instanceof Image || $xobject instanceof Form) {
// If the PDFObject is an Image, do nothing as images
// aren't text.
if ($xobject instanceof Image) {
break;
}

// Check this is not a circular reference.
if (!\in_array($xobject->getUniqueId(), self::$recursionStack, true)) {
$text[] = $xobject->getText($page);
if (\in_array($xobject->getUniqueId(), self::$recursionStack, true)) {
break;
}

$objectText = $xobject->getText($page);

// If the PDFObject is a Form and doesn't have any text,
// skip it.
if (($xobject instanceof Form) && ($objectText === ' ')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (($xobject instanceof Form) && ($objectText === ' ')) {
if ($xobject instanceof Form && $objectText === ' ') {

No parentheses required when using a combination of simple checks.

break;
}

$text[] = $objectText;
break;

// Marked content point with (DP) & without (MP) property list
Expand Down