mpdf import all pages from another pdf document

狂风中的少年 提交于 2019-12-12 08:38:17

问题


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?


回答1:


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();



回答2:


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);
}


来源:https://stackoverflow.com/questions/17992952/mpdf-import-all-pages-from-another-pdf-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!