我在使用 TCPDF 时遇到问题,因为我尝试设置在 header 输出后要在页面上打印的第一行文本的 Y 值,并且它被忽略。我的 header 例程位于扩展 TCPDF 类中,如下所示:
public function Header() {
$this->setJPEGQuality(90);
$this->Image('/www/images/hdrlogo.gif', 5, 20, 150, 0, 'GIF', 'https://www.example.com');
$this->SetFont(PDF_FONT_NAME_MAIN, 'B', 14);
$this->SetY(23);
$this->cell(0,20,"Activity Report",0,0,"R");
$this->SetFont(PDF_FONT_NAME_MAIN, 'R', 11);
$when=date("m/d/Y");
$this->SetY(41);
$this->cell(0,20,"Prepared $when",0,0,"R");
$this->Line(170,43,587,43);
$this->SetY($this->topMargin);
}
无论 $this->topMargin 中的值如何, header 输出后 Y 值均不受影响。我需要设置 Y 值的原因是,当 HTML 溢出页面时,我需要在标题信息之后在页面上开始溢出文本。标题在页面上看起来很好。这是执行此操作的正确方法还是 TCPDF 中还有其他方法吗?
最佳答案
你可以试试这个
.....
$margin = $this->getMargins();
$this->SetY($margin['top']);
.....
方法getMargins()
返回一个包含当前边距的数组。欲了解更多信息,您可以访问http://www.tcpdf.org/doc/code/classTCPDF.html#ae9bd660bf5b5e00eea82f1168cc67b5b
关于php - TCPDF 如何设置标题中的上边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25934841/