php - TCPDF 如何设置标题中的上边距

标签 php tcpdf

我在使用 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/

相关文章:

php - 包含两个字段的 MySQL 查询

php - TCPDF:Pdf 顶部始终有一个 hr 行

使用命名空间的 PHP 类会导致我的不使用命名空间的代码出现问题。为什么?

javascript - 在超过 1000 页的 PDF 文件中搜索文本

php - 如何在 TCPDF 中支持 UTF-8?

php - 类似于 Facebook 的 Mysql 结构

php - 我可以在 Laravel 5.2 中创建一个继承自 User 的新类吗?

php - 上传图片表格和另一个填写表格

当 header 有附件时,PHP Sendmail 发件人名称始终为 Apache

php - 阿拉伯语的 tcpdf 将字符显示为问号 '?????? ???'