public function getPage($pageNumber)
    {
        if (!\is_numeric($pageNumber)) {
            throw new \InvalidArgumentException(
                'Page number needs to be a number.'
            );
        }

        if ($pageNumber < 1 || $pageNumber > $this->getPageCount()) {
            throw new \InvalidArgumentException(
                \sprintf(
                    'Page number "%s" out of available page range (1 - %s)',
                    $pageNumber,
                    $this->getPageCount()
                )
            );
        }

        $this->readPages();

        $page = $this->pages[$pageNumber - 1];

        if ($page instanceof PdfIndirectObjectReference) {
            $readPages = function ($kids) use (&$readPages) {
                $kids = PdfArray::ensure($kids);

                /** @noinspection LoopWhichDoesNotLoopInspection */
                foreach ($kids->value as $reference) {
                    $reference = PdfIndirectObjectReference::ensure($reference);
                    $object = $this->parser->getIndirectObject($reference->value);
                    $type = PdfDictionary::get($object->value, 'Type');

                    if ($type->value === 'Pages') {
                        return $readPages(PdfDictionary::get($object->value, 'Kids'));
                    }

                    return $object;
                }

                throw new PdfReaderException(
                    'Kids array cannot be empty.',
                    PdfReaderException::KIDS_EMPTY
                );
            };

            $page = $this->parser->getIndirectObject($page->value);
            $dict = PdfType::resolve($page, $this->parser);
            $type = PdfDictionary::get($dict, 'Type');
            if ($type->value === 'Pages') {
                $kids = PdfType::resolve(PdfDictionary::get($dict, 'Kids'), $this->parser);
                $page = $this->pages[$pageNumber - 1] = $readPages($kids);
            } else {
                $this->pages[$pageNumber - 1] = $page;
            }
        }

        return new Page($page, $this->parser);
    }
public function getPage($pageNumber)
    {
        if (!\is_numeric($pageNumber)) {
            throw new \InvalidArgumentException(
                'Page number needs to be a number.'
            );
        }

        if ($pageNumber < 1 || $pageNumber > $this->getPageCount()) {
            throw new \InvalidArgumentException(
                \sprintf(
                    'Page number "%s" out of available page range (1 - %s)',
                    $pageNumber,
                    $this->getPageCount()
                )
            );
        }

        $this->readPages();

        $page = $this->pages[$pageNumber - 1];

        if ($page instanceof PdfIndirectObjectReference) {
            $readPages = function ($kids) use (&$readPages) {
                $kids = PdfArray::ensure($kids);

                /** @noinspection LoopWhichDoesNotLoopInspection */
                foreach ($kids->value as $reference) {
                    $reference = PdfIndirectObjectReference::ensure($reference);
                    $object = $this->parser->getIndirectObject($reference->value);
                    $type = PdfDictionary::get($object->value, 'Type');

                    if ($type->value === 'Pages') {
                        return $readPages(PdfDictionary::get($object->value, 'Kids'));
                    }

                    return $object;
                }

                throw new PdfReaderException(
                    'Kids array cannot be empty.',
                    PdfReaderException::KIDS_EMPTY
                );
            };

            $page = $this->parser->getIndirectObject($page->value);
            $dict = PdfType::resolve($page, $this->parser);
            $type = PdfDictionary::get($dict, 'Type');
            if ($type->value === 'Pages') {
                $kids = PdfType::resolve(PdfDictionary::get($dict, 'Kids'), $this->parser);
                $page = $this->pages[$pageNumber - 1] = $readPages($kids);
            } else {
                $this->pages[$pageNumber - 1] = $page;
            }
        }

        return new Page($page, $this->parser);
    }
public function getPage ( $ pageNumber ) { if ( ! \ is_numeric ( $ pageNumber ) ) { throw new \ InvalidArgumentException ( 'Page number needs to be a number.' ) ; } if ( $ pageNumber < 1 || $ pageNumber > $ this -> getPageCount ( ) ) { throw new \ InvalidArgumentException ( \ sprintf ( 'Page number "%s" out of available page range (1 - %s)' , $ pageNumber , $ this -> getPageCount ( ) ) ) ; } $ this -> readPages ( ) ; $ page = $ this -> pages [ $ pageNumber - 1 ] ; if ( $ page instanceof PdfIndirectObjectReference ) { $ readPages = function ( $ kids ) use ( & $ readPages ) { $ kids = PdfArray :: ensure ( $ kids ) ; /** @noinspection LoopWhichDoesNotLoopInspection */ foreach ( $ kids -> value as $ reference ) { $ reference = PdfIndirectObjectReference :: ensure ( $ reference ) ; $ object = $ this -> parser -> getIndirectObject ( $ reference -> value ) ; $ type = PdfDictionary :: get ( $ object -> value , 'Type' ) ; if ( $ type -> value === 'Pages' ) { return $ readPages ( PdfDictionary :: get ( $ object -> value , 'Kids' ) ) ; } return $ object ; } throw new PdfReaderException ( 'Kids array cannot be empty.' , PdfReaderException :: KIDS_EMPTY ) ; } ; $ page = $ this -> parser -> getIndirectObject ( $ page -> value ) ; $ dict = PdfType :: resolve ( $ page , $ this -> parser ) ; $ type = PdfDictionary :: get ( $ dict , 'Type' ) ; if ( $ type -> value === 'Pages' ) { $ kids = PdfType :: resolve ( PdfDictionary :: get ( $ dict , 'Kids' ) , $ this -> parser ) ; $ page = $ this -> pages [ $ pageNumber - 1 ] = $ readPages ( $ kids ) ; } else { $ this -> pages [ $ pageNumber - 1 ] = $ page ; } } return new Page ( $ page , $ this -> parser ) ; }
Get a page instance.

@param int $pageNumber
@return Page
@throws PdfTypeException
@throws CrossReferenceException
@throws PdfParserException
@throws \InvalidArgumentException
Get a page instance .