--- PDF\API2\Basic\PDF\Pages.old Fri Jul 7 04:53:59 2017 +++ PDF\API2\Basic\PDF\Pages.pm Tue Mar 26 12:24:25 2019 @@ -191,7 +191,7 @@ { for ($pindex = 0; $pindex < $ppnum; $pindex++) { last if ($ppages->{'Kids'}{' val'}[$pindex] eq $ppage); } - $pindex = -1 if ($pindex == $ppnum); + $pindex = -1 if ($pindex == $ppnum - 1); } $ppages->add_page_recurse($page->realise, $pindex); @@ -216,7 +216,7 @@ $ppnum = scalar $ppages->{'Kids'}->realise->elementsof; for ($pindex = 0; $pindex < $ppnum; $pindex++) { last if ($ppages->{'Kids'}{' val'}[$pindex] eq $self); } - $pindex = -1 if ($pindex == $ppnum); + $pindex = -1 if ($pindex == $ppnum - 1); $ppages->add_page_recurse($newpages, $pindex); } }