Import pages from existing PDF documents and use them as templates in FPDF

FPDI

Import pages from existing PDF documents and use them as templates in FPDF

Keep Links of Imported PDF Pages with FPDI

As of version 2.4.0 FPDI will copy link annotations with URI actions. This demo shows the new behavior which needs to be activated by the $importExternalLinks parameter of the importPage() method:

PHP
<?php

use setasign\Fpdi\Fpdi;
use setasign\Fpdi\PdfReader\PageBoundaries;

require_once('fpdf/fpdf.php');
require_once('fpdi2/src/autoload.php');

// initiate FPDI
$pdf = new Fpdi();
// add a page
$pdf->AddPage();
// set the source file
$pdf->setSourceFile('PdfDocument.pdf');
// import page 1 with links (4th parameter - $importExternalLinks set to true)
$tplIdx = $pdf->importPage(1, PageBoundaries::CROP_BOX, true, true);

// now we reuse the template several times and all links will be kept
$pdf->useTemplate($tplIdx, 10, 10, 100);
$pdf->useTemplate($tplIdx, 0, 70, 200);
$pdf->useTemplate($tplIdx, 30, 200, 120);

$pdf->Output('I', 'generated.pdf');