Mpdf import all pages from another pdf document

I want to be able to add the entire PDF document to the document that I create using 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, not just the last page?

+7
source share
3 answers

Use the page counter, you get the source file that sets the form in a loop (for example, below)

 $pdf = new mPDF(); $pdf->SetImportUse(); $pagecount = $pdf->SetSourceFile($dashboard_pdf_file); for ($i=1; $i<=$pagecount; $i++) { $import_page = $pdf->ImportPage(); $pdf->UseTemplate($import_page); if ($i < $pagecount) $pdf->AddPage(); } $pdf->Output(); 
+9
source

In this 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); } 
+22
source

This is the correct code.

 $pdf = new mPDF(); $pdf->SetImportUse(); $pagecount = $pdf->SetSourceFile($filename); for ($i=1; $i<=$pagecount; $i++) { $import_page = $pdf->ImportPage($i); $pdf->UseTemplate($import_page); if ($i < $pagecount) $pdf->AddPage(); } $pdf->Output(); exit; 
0
source

Source: https://habr.com/ru/post/950810/


All Articles