Count the pages in the most recent PDF export

@return int
169202
public function countPagesInMostRecentPdf() {
		$files = \Pressbooks\Utility\group_exports();

		if ( empty( $files ) ) {
			return 0;
		}

		foreach ( $files as $date => $exports ) {
			foreach ( $exports as $file ) {
				$file_extension = substr( strrchr( $file, '.' ), 1 );
				if ( 'pdf' === $file_extension ) {
					$path_to_pdf = \Pressbooks\Modules\Export\Export::getExportFolder() . $file;
					break 2;
				}
			}
		}

		if ( empty( $path_to_pdf ) ) {
			return 0;
		}

		try {
			return $this->countPagesInPdf( $path_to_pdf );
		} catch ( \Exception $e ) {
			return 0;
		}
	}
941983
public function getPage(): int {
        if ($this->getLimit() === 0) {
            return 1;
        }
        $result = floor($this->getOffset() / (int)$this->getLimit()) + 1;
//        $result = intdiv($this->getOffset(), (int)$this->getLimit()) + 1;
        return (int)$result;
    }
160983
private function get_page_count()
    {
        if ($this->wp_query instanceof WP_User_Query) {
            if (empty($this->wp_query->get_results())) {
                return 0;
            }

            return \ceil($this->wp_query->get_total() / $this->wp_query->query_vars['number']);
        }

        return (int) $this->wp_query->max_num_pages;
    }
502248
public function objectsPerPage()
    {
        $perPage = 10;
        if (!empty($this->headers[self::PER_PAGE]) && is_array($this->headers[self::PER_PAGE])) {
            $perPage = (int) $this->headers[self::PER_PAGE][0];
        }

        return $perPage;
    }
653952
def _previous_pages_count(self):
        ''
        skip = self.skip
        if skip == 0:
            return 0
        count, remainder = divmod(skip, self.limit)
        return count
153677
public function count(): int
    {
        $collection = $this->documentManager->getCollection($this->documentClass);

        return $collection->count($this->query);
    }
791051
function new_page() {
		//Helpers::dompdf_debug("trace", "()");

		// Add objects to the current page
		$this->_place_objects();

		//$this->_pdf->endPage();
		$this->_pdf->lastPage();

		$this->_pdf->AddPage();
		//$this->_page_count++;
		$this->_pages[] = $this->_pdf->PageNo();
		return $this->_pdf->getNumPages();
	}
1201229
protected function calculateCurrentPage($lastPage)
	{
		$page = $this->env->getCurrentPage();

		// The page number will get validated and adjusted if it either less than one
		// or greater than the last page available based on the count of the given
		// items array. If it's greater than the last, we'll give back the last.
		if (is_numeric($page) && $page > $lastPage)
		{
			return $lastPage > 0 ? $lastPage : 1;
		}

		return $this->isValidPageNumber($page) ? (int) $page : 1;
	}
584704
public function getNextPage()
    {
        $nextPage = $this->getPage() + 1;
        $lastPage = $this->getLastPage();
        if ($lastPage < $nextPage) {
            $nextPage = $lastPage;
        }

        return $nextPage;
    }
485532
function RenderPageCount()
	{
		if (!$this->db->pageExecuteCountRows) return '';
		$lastPage = $this->rs->LastPageNo();
		if ($lastPage == -1) $lastPage = 1; // check for empty rs.
		if ($this->curr_page > $lastPage) $this->curr_page = 1;
		return "<font size=-1>$this->page ".$this->curr_page."/".$lastPage."</font>";
	}
754411
public function getApproximatePageCount()
    {
        $siteTreeIDList = array_merge([0], $this->getSiteTreesIDList());
        $connection = $this->getConnection();
        $result = $connection->fetchColumn('select count(*) from Pages where siteTreeID is null or siteTreeID in (' . implode(', ', $siteTreeIDList) . ')');

        return $result ?: 0;
    }
12915
public function getLastPageNumber()
    {
        $this->loadData();
        $count = count($this->filteredData);

        return ceil($count / $this->pageSize);
    }
88545
public function paginate()
    {
        $totalCount = $this->getCount();

        $pageCount = $this->maxResults ? intval(ceil($totalCount / $this->maxResults)) : 1;
        $current = $this->page;
        $pageRange = 5;

        if ($pageCount < $current) {
            $current = $pageCount;
        }

        if ($pageRange > $pageCount) {
            $pageRange = $pageCount;
        }

        $delta = ceil($pageRange / 2);

        if ($current - $delta > $pageCount - $pageRange) {
            $pages = range($pageCount - $pageRange + 1, $pageCount);
        } else {
            if ($current - $delta < 0) {
                $delta = $current;
            }

            $offset = $current - $delta;
            $pages = range($offset + 1, $offset + $pageRange);
        }

        $proximity = floor($pageRange / 2);

        $startPage = $current - $proximity;
        $endPage = $current + $proximity;

        if ($startPage < 1) {
            $endPage = min($endPage + (1 - $startPage), $pageCount);
            $startPage = 1;
        }

        if ($endPage > $pageCount) {
            $startPage = max($startPage - ($endPage - $pageCount), 1);
            $endPage = $pageCount;
        }

        $pagination = [
            'last' => (int)$pageCount,
            'current' => (int)$current,
            'numItemsPerPage' => $this->maxResults ?? ucfirst(self::ALL_PARAMETER),
            'first' => 1,
            'pageCount' => (int)$pageCount,
            'totalCount' => (int)$totalCount,
            'pageRange' => $pageRange,
            'startPage' => (int)$startPage,
            'endPage' => (int)$endPage,
            'route' => $this->route,
            'routeParams' => $this->routeParams,
            'query' => $this->queryFilter,
            'pageParameterName' => 'page',
            'sort' => $this->sort,
        ];

        if ($current - 1 > 0) {
            $pagination['previous'] = $current - 1;
        }

        if ($current + 1 <= $pageCount) {
            $pagination['next'] = $current + 1;
        }

        $pagination['pagesInRange'] = $pages;
        $pagination['firstPageInRange'] = min($pages);
        $pagination['lastPageInRange'] = max($pages);

        $items = $this->getRecords();
        if ($items !== null) {
            $pagination['currentItemCount'] = (int)$totalCount;
            $pagination['firstItemNumber'] = $this->maxResults ? (($current - 1) * $this->maxResults) + 1 : 1;
            $pagination['lastItemNumber'] =  $pagination['firstItemNumber'] + $pagination['currentItemCount'] - 1;
        }

        return [
            'items' => $items,
            'pagination' => $pagination
        ];
    }
135935
public function currentPage()
    {
        $currentRoute = $this->router->getCurrentRoute();

        if (! $currentRoute) {
            return 1;
        }

        $query = $currentRoute->parameter('pageQuery');

        return (int) str_replace($this->pageKeyword.'/', '', $query) ?: 1;
    }
401028
protected function getCurrentPageAncestry()
    {
        $tools = ViewTools::singleton();
        
        if (($page = Director::get_current_page()) && $page instanceof Page) {
            return $tools->array2att($tools->getAncestorClassNames($page, Page::class));
        }
    }
304119
public function getTotalPages()
    {
        if (empty($this->totalPages)) {
            $this->totalPages = (int)ceil($this->getCursor()->count()/$this->limit);
        }

        return $this->totalPages;
    }
869808
private function getPagesCount()
    {
        if ($this->getItemsPerPage() != 0) {
            return (int) abs(ceil($this->getTotalAmount() / $this->getItemsPerPage()));
        } else {
            return 0;
        }
    }