src/FpdiTrait.php
public function getImportedExternalPageLinks($pageNumber)
	{
		$links = [];

		$reader = $this->getPdfReader($this->currentReaderId);
		$parser = $reader->getParser();

		$page = $reader->getPage($pageNumber);
		$page->getPageDictionary();

		$annotations = $page->getAttribute('Annots');
		if ($annotations instanceof PdfIndirectObjectReference) {
			$annotations = PdfType::resolve($parser->getIndirectObject($annotations->value), $parser);
		}

		if ($annotations instanceof PdfArray) {

			$getAttribute = function ($array, $key) {
				if (isset($array[$key]->value)) {
					return $array[$key]->value;
				}

				return '';
			};

			foreach ($annotations->value as $annotation) {
				$annotation = PdfType::resolve($annotation, $parser)->value;

				/* Skip over any annotations that aren't links */
				$type = $getAttribute($annotation, 'Type');
				$subtype = $getAttribute($annotation, 'Subtype');
				if ($type !== 'Annot' || $subtype !== 'Link' || !isset($annotation['A'])) {
					continue;
				}

				/* Calculate the link positioning */
				$position = $getAttribute($annotation, 'Rect');

				if (count($position) !== 4) {
					continue;
				}

				$x1 = $getAttribute($position, 0) / Mpdf::SCALE;
				$y1 = $getAttribute($position, 1) / Mpdf::SCALE;
				$x2 = $getAttribute($position, 2) / Mpdf::SCALE;
				$y2 = $getAttribute($position, 3) / Mpdf::SCALE;
				$width = $x2 - $x1;
				$height = $y2 - $y1;

				$link = $annotation['A'] instanceof PdfIndirectObjectReference ? PdfType::resolve($annotation['A'], $parser)->value : $getAttribute($annotation, 'A');

				if (isset($link['URI'])) {
					$links[] = [
						'x' => $x1,
						'y' => $y1,
						'width' => $width,
						'height' => $height,
						'url' => $getAttribute($link, 'URI')
					];
				}
			}
		}

		return $links;
	}
public function getImportedExternalPageLinks($pageNumber)
	{
		$links = [];

		$reader = $this->getPdfReader($this->currentReaderId);
		$parser = $reader->getParser();

		$page = $reader->getPage($pageNumber);
		$page->getPageDictionary();

		$annotations = $page->getAttribute('Annots');
		if ($annotations instanceof PdfIndirectObjectReference) {
			$annotations = PdfType::resolve($parser->getIndirectObject($annotations->value), $parser);
		}

		if ($annotations instanceof PdfArray) {

			$getAttribute = function ($array, $key) {
				if (isset($array[$key]->value)) {
					return $array[$key]->value;
				}

				return '';
			};

			foreach ($annotations->value as $annotation) {
				$annotation = PdfType::resolve($annotation, $parser)->value;

				/* Skip over any annotations that aren't links */
				$type = $getAttribute($annotation, 'Type');
				$subtype = $getAttribute($annotation, 'Subtype');
				if ($type !== 'Annot' || $subtype !== 'Link' || !isset($annotation['A'])) {
					continue;
				}

				/* Calculate the link positioning */
				$position = $getAttribute($annotation, 'Rect');

				if (count($position) !== 4) {
					continue;
				}

				$x1 = $getAttribute($position, 0) / Mpdf::SCALE;
				$y1 = $getAttribute($position, 1) / Mpdf::SCALE;
				$x2 = $getAttribute($position, 2) / Mpdf::SCALE;
				$y2 = $getAttribute($position, 3) / Mpdf::SCALE;
				$width = $x2 - $x1;
				$height = $y2 - $y1;

				$link = $annotation['A'] instanceof PdfIndirectObjectReference ? PdfType::resolve($annotation['A'], $parser)->value : $getAttribute($annotation, 'A');

				if (isset($link['URI'])) {
					$links[] = [
						'x' => $x1,
						'y' => $y1,
						'width' => $width,
						'height' => $height,
						'url' => $getAttribute($link, 'URI')
					];
				}
			}
		}

		return $links;
	}
public function getImportedExternalPageLinks ( $ pageNumber ) { $ links = [ ] ; $ reader = $ this -> getPdfReader ( $ this -> currentReaderId ) ; $ parser = $ reader -> getParser ( ) ; $ page = $ reader -> getPage ( $ pageNumber ) ; $ page -> getPageDictionary ( ) ; $ annotations = $ page -> getAttribute ( 'Annots' ) ; if ( $ annotations instanceof PdfIndirectObjectReference ) { $ annotations = PdfType :: resolve ( $ parser -> getIndirectObject ( $ annotations -> value ) , $ parser ) ; } if ( $ annotations instanceof PdfArray ) { $ getAttribute = function ( $ array , $ key ) { if ( isset ( $ array [ $ key ] -> value ) ) { return $ array [ $ key ] -> value ; } return '' ; } ; foreach ( $ annotations -> value as $ annotation ) { $ annotation = PdfType :: resolve ( $ annotation , $ parser ) -> value ; /* Skip over any annotations that aren't links */ $ type = $ getAttribute ( $ annotation , 'Type' ) ; $ subtype = $ getAttribute ( $ annotation , 'Subtype' ) ; if ( $ type !== 'Annot' || $ subtype !== 'Link' || ! isset ( $ annotation [ 'A' ] ) ) { continue ; } /* Calculate the link positioning */ $ position = $ getAttribute ( $ annotation , 'Rect' ) ; if ( count ( $ position ) !== 4 ) { continue ; } $ x1 = $ getAttribute ( $ position , 0 ) / Mpdf :: SCALE ; $ y1 = $ getAttribute ( $ position , 1 ) / Mpdf :: SCALE ; $ x2 = $ getAttribute ( $ position , 2 ) / Mpdf :: SCALE ; $ y2 = $ getAttribute ( $ position , 3 ) / Mpdf :: SCALE ; $ width = $ x2 - $ x1 ; $ height = $ y2 - $ y1 ; $ link = $ annotation [ 'A' ] instanceof PdfIndirectObjectReference ? PdfType :: resolve ( $ annotation [ 'A' ] , $ parser ) -> value : $ getAttribute ( $ annotation , 'A' ) ; if ( isset ( $ link [ 'URI' ] ) ) { $ links [ ] = [ 'x' => $ x1 , 'y' => $ y1 , 'width' => $ width , 'height' => $ height , 'url' => $ getAttribute ( $ link , 'URI' ) ] ; } } } return $ links ; }
Imports the external page links

@param int $pageNumber The page number.
@return array
@throws CrossReferenceException
@throws PdfTypeException
@throws \setasign\Fpdi\PdfParser\PdfParserException
Imports the external page links