bub*_*aba 10 php pdf pdf-generation tcpdf
有没有办法在文档中为第一页设置不同的标题徽标,在第二页中有不同的标题?
我认为在添加页面之间更改标题数据可能会有所帮助,但在我的测试中,似乎在添加第一页后设置标题没有效果:
/* other stuff
$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->AliasNbPages();
*/
$pdf->SetHeaderData("logo_1.png", PDF_HEADER_LOGO_WIDTH, '', '');
$pdf->AddPage();
$pdf->writeHTML($htmlContent, true, 0, true, true);
$pdf->SetHeaderData("logo_2.png", PDF_HEADER_LOGO_WIDTH, '', '');
$pdf->AddPage();
$pdf->writeHTML($htmlContent2, true, 0, true, true);
Run Code Online (Sandbox Code Playgroud)
上面会生成一个包含2页的文档,两个页面都有logo_1.png标题.
我需要自定义TCPDF吗?有没有人这样做过?我正在使用版本5.9.144.
奇怪.我有同样的问题,但这适用于我的旧版TCPDF版本:4.8.009,当我升级到5.9.149时,我注意到了这个问题.
我比较了2并将问题与Header()函数隔离开来.
我可以强制它允许我更改标题并通过运行它来接受它:$ pdf-> setHeaderTemplateAutoreset(true);
小智 6
以下对我有用,
class MYPDF extends TCPDF{
function header1(){
//print whatever the header 1 is
}
function Header2(){
if($this->page==1){
//print header 1 and whatever the header 2 is
}else{
//print just header 2
}
}
}
Run Code Online (Sandbox Code Playgroud)