Pop\Pdf\Import::getObjects PHP Метод

getObjects() защищенный Метод

Method to search and return the objects within in the imported data.
protected getObjects ( string $data ) : void
$data string
Результат void
    protected function getObjects($data)
    {
        // Grab object start points.
        preg_match_all('/\\d*\\s\\d*\\sobj/', $data, $matches, PREG_OFFSET_CAPTURE);
        if (isset($matches[0])) {
            $obj_start = $matches[0];
            // Start parsing through the object data.
            for ($i = 0; $i < count($obj_start); $i++) {
                $type = '';
                $j = $i + 1;
                $index = substr($obj_start[$i][0], 0, strpos($obj_start[$i][0], ' '));
                if (array_key_exists($j, $obj_start)) {
                    $obj_data = substr($data, $obj_start[$i][1], $obj_start[$j][1] - $obj_start[$i][1]);
                } else {
                    $obj_data = substr($data, $obj_start[$i][1], strrpos($data, 'endobj') - $obj_start[$i][1] + 6);
                }
                // Add all relevant objects, striping away any linearized code, hint codes or metadata, as the order and size of the PDF and its objects may change.
                if (strpos($obj_data, '/Linearized') === false && strpos($obj_data, '/Type/Metadata') === false) {
                    if (strpos($obj_data, '/Catalog') !== false && strpos($obj_data, '/Pages') !== false) {
                        // Strip away any metadata references.
                        $metadata = substr($obj_data, strpos($obj_data, 'Metadata'));
                        $metadata = '/' . substr($metadata, 0, strpos($metadata, '/'));
                        $obj_data = str_replace($metadata, '', $obj_data);
                        $type = 'root';
                    } else {
                        if (strpos($obj_data, '/Creator') !== false || strpos($obj_data, '/Producer') !== false) {
                            $type = 'info';
                        } else {
                            if (strpos($obj_data, '/Count') !== false && strpos($obj_data, '/Kids') !== false) {
                                $kids = substr($obj_data, strpos($obj_data, 'Kids'));
                                $kids = substr($kids, 0, strpos($kids, ']'));
                                $kids = str_replace('Kids', '', $kids);
                                $kids = str_replace('[', '', $kids);
                                $kids = str_replace(' 0 R', '|', $kids);
                                $kids = str_replace(' ', '', $kids);
                                $kids = substr($kids, 0, -1);
                                $kids_objs = explode('|', $kids);
                                $this->kids = $kids_objs;
                                $type = 'parent';
                            } else {
                                if (strpos($obj_data, '/MediaBox') !== false || strpos($obj_data, '/Contents') !== false) {
                                    if (strpos($obj_data, '/Thumb') !== false) {
                                        // Strip away any thumbnail references.
                                        $thumbdata = substr($obj_data, strpos($obj_data, 'Thumb'));
                                        $thumbdata = '/' . substr($thumbdata, 0, strpos($thumbdata, '/'));
                                        $thumbindex = substr($thumbdata, strpos($thumbdata, ' '));
                                        $thumbindex = str_replace(' 0 R', '', $thumbindex);
                                        $thumbindex = str_replace(' ', '', $thumbindex);
                                        $this->thumbs[] = $thumbindex;
                                        $obj_data = str_replace($thumbdata, '', $obj_data);
                                    }
                                    $type = 'page';
                                } else {
                                    $type = 'content';
                                }
                            }
                        }
                    }
                    $this->objects[$index] = array('type' => $type, 'data' => $obj_data, 'refs' => $this->getRefs($obj_data));
                }
            }
            // Order the page objects correctly.
            $pageOrder = array();
            foreach ($this->objects as $key => $value) {
                if ($value['type'] == 'page') {
                    $pageOrder[$key] = $value;
                    unset($this->objects[$key]);
                }
            }
            foreach ($this->kids as $value) {
                if (isset($pageOrder[$value])) {
                    $this->objects[$value] = $pageOrder[$value];
                }
            }
            // Remove any thumbnail objects.
            if (count($this->thumbs) != 0) {
                foreach ($this->thumbs as $value) {
                    unset($this->objects[$value]);
                }
            }
        }
    }