Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mpdf import all pages from another pdf document

Tags:

import

pdf

mpdf

I want to be able to append an entire pdf document in the document I am creating with mpdf.

I can import one page using the following code:

$mpdf->SetImportUse(); 

$pagecount = $mpdf->SetSourceFile('testfile.pdf');

$tplId = $mpdf->ImportPage($pagecount, 50, 50, 100, 100);

$mpdf->UseTemplate($tplId, '', '', 100, 100);

$mpdf->Output();

but is there a way to import all pages rather than just the last page?

like image 683
Jamie Hall Avatar asked Aug 01 '13 11:08

Jamie Hall


1 Answers

In the example the index in "$pdf->ImportPage($i)" is missing.

$pdf->SetImportUse();
$pagecount = $pdf->SetSourceFile([LOCAL_FILEPATH]);
for ($i=1; $i<=($pagecount); $i++) {
    $pdf->AddPage();
    $import_page = $pdf->ImportPage($i);
    $pdf->UseTemplate($import_page);
}
like image 143
Thomas Avatar answered Sep 21 '22 18:09

Thomas