duanbi7247 2017-06-11 21:40
浏览 303

MPDF,将PDF与几页合并,使用当前页面

I have the following code which downloads a PDF and I am trying to add some more pages from another PDF, after the current one:

$html = 'THIS IS A ONE PAGE PDF';

include ("PDF/mpdf60/mpdf.php");
$mpdf = new mPDF('c', 'A4-L','','' , 0, 0, 0, 0, 0, 0); 
$mpdf->WriteHTML(utf8_encode($html));

$mpdf->AddPage();
$mpdf->SetImportUse();
$file = './best.pdf'; // HERE IS THE SECOND PDF WHICH I WANT TO MERGE WITH THE CURRENT ONE
$pagecount = $mpdf->SetSourceFile($file);
$tplId = $mpdf->ImportPage($pagecount);

$mpdf->UseTemplate($tplId);
ob_end_clean();
$mpdf->Output("title" . date('d-m-Y') . ".pdf",'D');
exit;

I can t get it to a solution. It creates a PDF where the last page from the best.pdf gets over my current first page pdf.

enter image description here

EDIT: I added $mpdf->AddPage(); before $mpdf->SetImportUse(); and now I get the last page from the second pdf into the second page in first PDF. All I have to do now is to get all pages from the best.pdf.

  • 写回答

1条回答 默认 最新

  • duanlinma5885 2017-06-11 22:42
    关注

    I managed to do it like this:

    $html = 'SOME TEXT HERE FOR THE CURRENT PDF';
    include ("PDF/mpdf60/mpdf.php");
    $mpdf = new mPDF('c', 'A4-L','','' , 0, 0, 0, 0, 0, 0); 
    $mpdf->WriteHTML(utf8_encode($html));
    
    $mpdf->AddPage();
    $mpdf->SetImportUse();
    $file = './best.pdf';
    $pagecount = $mpdf->SetSourceFile($file);
        for ($i=1; $i<=$pagecount; $i++) {
            $import_page = $mpdf->ImportPage($i);
            $mpdf->UseTemplate($import_page);
    
            if ($i < $pagecount)
                $mpdf->AddPage();
        }
    ob_end_clean();
    $mpdf->Output("title" . date('d-m-Y') . ".pdf",'D');
    exit;
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料