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

returnObjects() публичный Метод

Method to return the desired imported objects to the main PDF object.
public returnObjects ( integer $par ) : array
$par integer
Результат array
    public function returnObjects($par)
    {
        $objs = array();
        $keys = array_keys($this->objects);
        foreach ($keys as $key) {
            // Skip the root, parent and info objects, returning only page and content objects.
            if ($this->objects[$key]['type'] != 'root' && $this->objects[$key]['type'] != 'parent' && $this->objects[$key]['type'] != 'info') {
                if ($this->objects[$key]['type'] == 'page') {
                    $parent = substr($this->objects[$key]['data'], strpos($this->objects[$key]['data'], 'Parent'));
                    $parent = substr($parent, 0, strpos($parent, '/'));
                    $parent = str_replace('Parent', '', $parent);
                    $parent = str_replace(' 0 R', '', $parent);
                    $parent = str_replace(' ', '', $parent);
                    $this->objects[$key]['data'] = str_replace('/Parent ' . $parent . ' 0 R', '/Parent ' . $par . ' 0 R', $this->objects[$key]['data']);
                    $this->objects[$key]['data'] = str_replace('/Parent [' . $parent . ' 0 R', '/Parent [' . $par . ' 0 R', $this->objects[$key]['data']);
                }
                $objs[$key] = $this->objects[$key];
            }
        }
        return $objs;
    }

Usage Example

Пример #1
0
 /**
  * Method to import either an entire PDF, or a page of a PDF, and the related data.
  *
  * @param  string           $pdf
  * @param  int|string|array $pg
  * @return \Pop\Pdf\Pdf
  */
 public function import($pdf, $pg = null)
 {
     // Create a new PDF Import object.
     $pdfi = new Import($pdf, $pg);
     // Shift the imported objects indices based on existing indices in this PDF.
     $pdfi->shiftObjects($this->lastIndex($this->objects) + 1);
     // Fetch the imported objects.
     $importedObjs = $pdfi->returnObjects($this->parent);
     // Loop through the imported objects, adding the pages or objects as applicable.
     foreach ($importedObjs as $key => $value) {
         if ($value['type'] == 'page') {
             // Add the page object.
             $this->objects[$key] = new Object\Page($value['data']);
             // Finalize related page variables and objects.
             $this->curPage = null === $this->curPage ? 0 : $this->lastIndex($this->pages) + 1;
             $this->pages[$this->curPage] = $key;
             $this->objects[$this->parent]->count += 1;
         } else {
             // Else, add the content object.
             $this->objects[$key] = new Object\Object($value['data']);
         }
     }
     foreach ($pdfi->pages as $value) {
         $this->objects[$this->parent]->kids[] = $value;
     }
     return $this;
 }