一直在使用TCPDF示例, 我已经制作了一份我想要运行的报告,4页,
前两页,1-2页只是背景图片, 即:(第1页)封面,(背景图片) (第2页)摘要图像(背景图像) (第3页)这是删除背景图像并使用标准标题的地方 (第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页上可以获得原始标题的唯一方法。 任何其他人对如何设置/重置标题有任何想法?
欢呼声