Example #1
0
 /**
  * Parse a stream object from a string
  *
  * @param  string $stream
  * @return StreamObject
  */
 public static function parse($stream)
 {
     $object = new self();
     $object->setIndex(substr($stream, 0, strpos($stream, ' ')));
     $stream = str_replace($object->getIndex() . ' 0 obj', '[{object_index}] 0 obj', $stream);
     // Determine the objects definition and stream, if applicable.
     $s = substr($stream, strpos($stream, ' obj') + 4);
     $s = substr($s, 0, strpos($s, 'endobj'));
     if (strpos($s, 'stream') !== false) {
         $def = substr($s, 0, strpos($s, 'stream'));
         $str = substr($s, strpos($s, 'stream') + 6);
         $str = substr($str, 0, strpos($str, 'endstream'));
         $object->setDefinition($def);
         $object->appendStream($str);
     } else {
         $object->setDefinition($s);
     }
     $object->setData("\n[{object_index}] 0 obj\n[{definition}]\n[{stream}]\nendobj\n\n");
     return $object;
 }