Skip to content

Commit

Permalink
Add PdfType::flatten() method
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSlabon committed Dec 6, 2023
1 parent 68a894e commit bb489d2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/PdfParser/Type/PdfType.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ protected static function ensureType($type, $value, $errorMessage)
return $value;
}

/**
* Flatten indirect object references to direct objects.
*
* @param PdfType $value
* @param PdfParser $parser
* @return PdfType
* @throws CrossReferenceException
* @throws PdfParserException
*/
public static function flatten(PdfType $value, PdfParser $parser)
{
if ($value instanceof PdfIndirectObjectReference) {
return self::flatten(self::resolve($value, $parser), $parser);
}

if ($value instanceof PdfDictionary || $value instanceof PdfArray) {
foreach ($value->value as $key => $_value) {
$value->value[$key] = self::flatten($_value, $parser);
}
}

if ($value instanceof PdfStream) {
throw new PdfTypeException('There is a stream object found which cannot be flattened to a direct object.');
}

return $value;
}

/**
* The value of the PDF type.
*
Expand Down

0 comments on commit bb489d2

Please sign in to comment.