How to overlay HTML generated PDF on top of existing PDF?

强颜欢笑 提交于 2019-11-28 13:05:36

For sure you can use different existing PDF documents with FPDI, too. This code should show you the concept (actually I guess that all page formats are A4 portrait):

<?php

$pdf = new FPDI();

// let's get an id for the background template
$pdf->setSourceFile('myPDF.pdf'); 
$backId = $pdf->importPage(1);

// iterate over all pages of HTML_Generated_pdf.pdf and import them
$pageCount = $pdf->setSourceFile('HTML_Generated_pdf.pdf');
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
    // add a page
    $pdf->AddPage();
    // add the background
    $pdf->useTemplate($backId);
    // import the content page
    $pageId = $pdf->importPage($pageNo);
    // add it
    $pdf->useTemplate($pageId);
}

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