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

前端 未结 1 497
情话喂你
情话喂你 2020-12-10 20:20

I\'m looking to start with an initial PDF file, one that has graphics and text, and then take some html code which has dynamic values for some user input, generate that as a

相关标签:
1条回答
  • 2020-12-10 20:45

    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();
    
    0 讨论(0)
提交回复
热议问题