mpdf import all pages from another pdf document

2019-04-07 05:27发布

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?

标签: pdf import mpdf
3条回答
Emotional °昔
2楼-- · 2019-04-07 05:56

Its a correctly 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;
查看更多
啃猪蹄的小仙女
3楼-- · 2019-04-07 06:10

Use page count you get form setting source file in a loop (like 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();
查看更多
兄弟一词,经得起流年.
4楼-- · 2019-04-07 06:17

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);
}
查看更多
登录 后发表回答