TCPDF set different headers for different pages in one document

后端 未结 8 623
终归单人心
终归单人心 2021-02-08 04:50

Is there a way to have a different header logo for the 1st page in a document and different for the 2nd page?

I thought that changing the header data between adding page

8条回答
  •  执笔经年
    2021-02-08 05:29

    Just for the record, if someone has the same problem in the future and can use Zend_Pdf:

    // $filename is the final filename with path to save the generated PDF
    $dir = dirname($filename);
    $base = basename($filename);
    
    $page1 = $dir . DIRECTORY_SEPARATOR . "tmp_1_" . $base;
    $page2 = $dir . DIRECTORY_SEPARATOR . "tmp_2_" . $base;
    
    //creates 1st page with TCPDF and saves to filesystem with filename $page1
    $this->generateInvoicePage1($html_1, $page1);
    
    //creates 2nd page with TCPDF and saves to filesystem with filename $page2
    $this->generateInvoicePage2($html_2, $page2);
    
    $pdf1 = Zend_Pdf::load($page1);
    $pdf2 = Zend_Pdf::load($page2);
    
    foreach ($pdf2->pages as $page) {
        $pdf1->pages[] = clone($page);
    }
    
    $pdf1->save($filename);
    
    unlink($page1);
    unlink($page2);
    

提交回复
热议问题