Example #1
0
function read_object($stream, $pdf)
{
    $tok = fread($stream, 1);
    fseek($stream, -1, 1);
    if ($tok == 't' || $tok == 'f') {
        return BooleanObject::read_from_stream($stream);
    } else {
        if ($tok == '(') {
            return read_string_from_stream($stream);
        } else {
            if ($tok == '/') {
                return NameObject::read_from_stream($stream);
            } else {
                if ($tok == '[') {
                    return ListObject::read_from_stream($stream, $pdf);
                } else {
                    if ($tok == 'n') {
                        return NullObject::read_from_stream($stream);
                    } else {
                        if ($tok == '<') {
                            $peek = fread($stream, 2);
                            fseek($stream, -2, 1);
                            if ($peek == '<<') {
                                $r = DictionaryObject::read_from_stream($stream, $pdf);
                                return $r;
                            } else {
                                return read_hex_string_from_stream($stream);
                            }
                        } else {
                            if ($tok == '%') {
                                while ($tok != "\r" && $tok != "\n") {
                                    $tok = fread($stream, 1);
                                }
                                $tok = read_non_whitespace($stream);
                                fseek($stream, -1, 1);
                                return read_object($stream, $pdf);
                            } else {
                                if ($tok == '+' || $tok == '-') {
                                    return NumberObject::read_from_stream($stream);
                                }
                                $peek = fread($stream, 20);
                                fseek($stream, -strlen($peek), 1);
                                if (preg_match("/^(\\d+)\\s(\\d+)\\sR[^a-zA-Z]/", $peek)) {
                                    return IndirectObject::read_from_stream($stream, $pdf);
                                } else {
                                    return NumberObject::read_from_stream($stream);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Example #2
0
 function get_object($indirect_ref)
 {
     $retval = $this->resolved_objects[$indirect_ref->generation];
     if ($retval) {
         $retval = $retval[$indirect_ref->idnum];
         if ($retval) {
             return $retval;
         }
     }
     if ($indirect_ref->generation === 0 and in_array($indirect_ref->idnum, array_keys($this->xref_obj_stm))) {
         $stm_num = $this->xref_obj_stm[$indirect_ref->idnum][0];
         $idx = $this->xref_obj_stm[$indirect_ref->idnum][1];
         $o = new IndirectObject($stm_num, 0, $this);
         $obj_stm = $o->get_object();
         $stream_data = tmpfile();
         fwrite($stream_data, $obj_stm->get_data());
         fseek($stream_data, 0);
         # !!!
         fseek($stream_data, 0);
         for ($i = 0; $i < $obj_stm->data['/N']; $i++) {
             $obj_num = NumberObject::read_from_stream($stream_data);
             read_non_whitespace($stream_data);
             fseek($stream_data, -1, 1);
             $offset = NumberObject::read_from_stream($stream_data);
             read_non_whitespace($stream_data);
             fseek($stream_data, -1, 1);
             $t = ftell($stream_data);
             fseek($stream_data, $obj_stm->data['/First'] + $offset, 0);
             $obj = read_object($stream_data, $this);
             $this->resolved_objects[0][$obj_num] = $obj;
             fseek($stream_data, $t, 0);
         }
         fclose($stream_data);
         return $this->resolved_objects[0][$indirect_ref->idnum];
     }
     $start = $this->xref[$indirect_ref->generation][$indirect_ref->idnum];
     fseek($this->stream, $start, 0);
     $header = $this->read_object_header($this->stream);
     $idnum = $header[0];
     $generation = $header[1];
     $retval = read_object($this->stream, $this);
     $this->cache_indirect_object($generation, $idnum, $retval);
     return $retval;
 }