将html写入自定义标头tcpdf

时间:2014-09-22 13:15:09

标签: tcpdf

我很难理解标题函数在tcpdf中是如何工作的。

是否可以将$ pdf-> writeHTML用于标题?

http://www.tcpdf.org/examples/example_003.phps

我想在标题中显示3列。

 Column1 Column2 Column3

3 个答案:

答案 0 :(得分:11)

问题解决了,归功于Simon @ https://sourceforge.net/p/tcpdf/discussion/435311/thread/505a9e13/

class MYPDF extends TCPDF {
public function Header() {
    $headerData = $this->getHeaderData();
    $this->SetFont('helvetica', 'B', 10);
    $this->writeHTML($headerData['string']);
}
}
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setHeaderData($ln='', $lw=0, $ht='', $hs='<table cellspacing="0" cellpadding="1" border="1">tr><td rowspan="3">test</td><td>test</td></tr></table>', $tc=array(0,0,0), $lc=array(0,0,0));

答案 1 :(得分:4)

问题解决了,这个方法不那么复杂,在标题

中插入HTML代码时更直接
class MYTCPDF extends TCPDF {

  public function Header(){
     $html = '<table cellspacing="0" cellpadding="1" border="0"><tr><td rowspan="3">test</td><td>test</td><td>test</td></tr></table>';
     $this->writeHTMLCell($w = 0, $h = 0, $x = '', $y = '', $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = 'top', $autopadding = true);
  }
    }

答案 2 :(得分:0)

这种方式也适用:

class MYPDF extends TCPDF{
    public function Header(){
        $html = '<table cellspacing="0" cellpadding="1" border="0"><tr><td rowspan="3">test</td><td>test</td><td>test</td></tr></table>';
        $this->writeHTML($html, true, false, false, false, '');
    }
}


$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setPrintHeader(true);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->Output('pdfHeader.pdf', 'I');