public function testShiftObjects() { $i = new Import(__DIR__ . '/../tmp/test.pdf'); $i->shiftObjects(5); $this->assertInstanceOf('Pop\\Pdf\\Import', $i); $this->assertTrue(is_array($i->returnObjects(2))); }
/** * 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; }