1

一直在使用 TCPDF 示例,我已经建立了一个我想运行的报告,4 页,

前几页,从 1-2 只是背景图片,即:(第一页)封面,(背景图片)(第二页)摘要图片(背景图片)(第三页)这是删除背景图片的地方,使用标准页眉(第 4 页)回到使用完整背景图像,

我正在使用示例 example_051.php 中的代码,包括扩展类,我假设它覆盖了 TCPDF 使用的主要 Header 函数,

class MYPDF extends TCPDF {
    //Page header
    public function Header() {
        // get the current page break margin
        $bMargin = $this->getBreakMargin();
        // get current auto-page-break mode
        $auto_page_break = $this->AutoPageBreak;
        // disable auto-page-break
        $this->SetAutoPageBreak(false, 0);
        // set bacground image
        if($this->page <= 1){
          $img_file = 'frontcover.jpg';
              $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
        }
        // restore auto-page-break status
        $this->SetAutoPageBreak($auto_page_break, $bMargin);
        // set the starting point for the page content
        $this->setPageMark();
    }
}

// PAGE 1 - BIG background image
$pdf->AddPage();
$bMargin = $pdf->getBreakMargin();
$auto_page_break = $pdf->getAutoPageBreak();
$pdf->SetAutoPageBreak(false, 0);
$img_file = 'frontcover.jpg';
$pdf->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
$pdf->SetAutoPageBreak($auto_page_break, $bMargin);
$pdf->setPageMark();


// PAGE 2 - BIG background image
$pdf->AddPage();
$bMargin = $pdf->getBreakMargin();
$auto_page_break = $pdf->getAutoPageBreak();
$pdf->SetAutoPageBreak(false, 0);
$img_file = 'frontpage-summary.jpg';
$pdf->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
$pdf->SetAutoPageBreak($auto_page_break, $bMargin);
$pdf->setPageMark();


// PAGE 3 - SET Header image
$pdf->setPrintHeader(true); // enable header
$pdf->setPrintFooter(false);// disable footer
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetHeaderData("header.png", PDF_HEADER_LOGO_WIDTH, "image title", "header string");

$pdf->AddPage();
$html.= '<div style="padding:10px;">';
$html.= '<h2>Report Title</h2>';
$html.= '<h3>sub title</h3>';
$html.= '<h2>Other Title</h2>';
$html.= '<h3>sub title</h3>';
$html.= '<h2>Other Title</h2>';
$html.= '<h3>sub title</h3>';
$html.= '</div>';
$pdf->writeHTML($html, true, false, true, false, '');


// PAGE 4
$pdf->AddPage();
$bMargin = $pdf->getBreakMargin();
$auto_page_break = $pdf->getAutoPageBreak();
$pdf->SetAutoPageBreak(false, 0);
$img_file = 'final-page.png';
$pdf->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
$pdf->SetAutoPageBreak($auto_page_break, $bMargin);
$pdf->setPageMark();
$pdf->lastPage();

Iv 尝试使用 resetHeaderTemplate() 函数重置标题,但第 3 页上的标题部分不会显示?

在扩展类中,我有点检查页面是否小于1,

if($this->page <= 1){
   $img_file = 'frontcover.jpg';
   $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
}

我所做的是将整个标头函数从 TCPDF.php 复制到 if else 所以现在它读取

if($this->page <= 1){
   $img_file = 'frontcover.jpg';
   $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
}else{
   // add the entire code from the original function :(
}

这似乎是我可以让我的原始标题回到第 3 页的唯一方法.. 任何其他人对如何设置/重置标题有任何想法?

干杯

4

0 回答 0