public function shiftObjects($si)
{
if ($this->firstIndex($this->objects) <= $si) {
ksort($this->objects);
$keyChanges = array();
$newObjects = array();
foreach ($this->objects as $key => $value) {
$keyChanges[$key] = $si;
$newObjects[$si] = $this->objects[$key];
if (substr($newObjects[$si]['data'], 0, strlen($key . ' 0 obj')) === $key . ' 0 obj') {
$newObjects[$si]['data'] = str_replace($key . ' 0 obj', $si . ' 0 obj', $newObjects[$si]['data']);
}
$si++;
}
$keyChanges = array_reverse($keyChanges, true);
foreach ($newObjects as $key => $obj) {
if (count($obj['refs']) > 0) {
$matches = array();
preg_match_all('/\\d+\\s0\\sR/mi', $newObjects[$key]['data'], $matches, PREG_OFFSET_CAPTURE);
if (isset($matches[0][0])) {
$start = count($matches[0]) - 1;
for ($i = $start; $i >= 0; $i--) {
$ref = $matches[0][$i][0];
$len = $matches[0][$i][1];
$k = substr($ref, 0, strpos($ref, ' '));
if (isset($keyChanges[$k])) {
$newObjects[$key]['data'] = substr_replace($newObjects[$key]['data'], $keyChanges[$k] . ' 0 R', $len, strlen($ref));
}
}
}
}
}
foreach ($this->pages as $k => $v) {
if (isset($keyChanges[$v])) {
$this->kids[$k] = $keyChanges[$v];
}
}
$this->objects = $newObjects;
$this->pages = $this->kids;
}
}