src/Pdf/Pdf.php
public function importPages(string $filePath): PdfInterface
    {
        if (!is_file($filePath)) {
            throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $filePath));
        }
        $numberPagesCurrentFile = count($this->mpdf->pages);
        $numberPagesExternalFile = $this->mpdf->setSourceFile($filePath);
        $numberTotalPages = $numberPagesCurrentFile + $numberPagesExternalFile;
        $this->mpdf->setImportUse();

        for ($i = 1; $i <= $numberPagesExternalFile; $i++) {
            if ($i < $numberTotalPages) {
                $this->mpdf->addPage();
            }
            $this->mpdf->useTemplate($this->mpdf->importPage($i));
        }

        return $this;
    }
public function importPages(string $filePath): PdfInterface
    {
        if (!is_file($filePath)) {
            throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $filePath));
        }
        $numberPagesCurrentFile = count($this->mpdf->pages);
        $numberPagesExternalFile = $this->mpdf->setSourceFile($filePath);
        $numberTotalPages = $numberPagesCurrentFile + $numberPagesExternalFile;
        $this->mpdf->setImportUse();

        for ($i = 1; $i <= $numberPagesExternalFile; $i++) {
            if ($i < $numberTotalPages) {
                $this->mpdf->addPage();
            }
            $this->mpdf->useTemplate($this->mpdf->importPage($i));
        }

        return $this;
    }
public function importPages ( string $ filePath ) : PdfInterface { if ( ! is_file ( $ filePath ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The file "%s" does not exist.' , $ filePath ) ) ; } $ numberPagesCurrentFile = count ( $ this -> mpdf -> pages ) ; $ numberPagesExternalFile = $ this -> mpdf -> setSourceFile ( $ filePath ) ; $ numberTotalPages = $ numberPagesCurrentFile + $ numberPagesExternalFile ; $ this -> mpdf -> setImportUse ( ) ; for ( $ i = 1 ; $ i <= $ numberPagesExternalFile ; $ i ++ ) { if ( $ i < $ numberTotalPages ) { $ this -> mpdf -> addPage ( ) ; } $ this -> mpdf -> useTemplate ( $ this -> mpdf -> importPage ( $ i ) ) ; } return $ this ; }
Import external file pages and merge with current.

@param string $filePath The path of the file to merge

@return PdfInterface The current interface

@throws \InvalidArgumentException if the parameter file does not exist

@api
Import external file pages and merge with current .