PHP TCPDF 删除标头的底部边框

发布于 2024-12-13 03:28:48 字数 53 浏览 3 评论 0原文

我试图在 TCPDF 中创建一个标头,但它下面总是有一个边框。有什么办法可以去掉底部边框吗?

I am trying to create a header in TCPDF, however it always have a border underneath of it. Is there a way I can remove the bottom border?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

迷爱 2024-12-20 03:28:48

这适用于某些版本:

// Call before the addPage() method
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);

This works for some versions:

// Call before the addPage() method
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
叹倦 2024-12-20 03:28:48

如果您不想子类化或更改 tcpdf 源,只需调用 setHeaderData 方法并指定白线颜色。

$pdf->setHeaderData('',0,'','',array(0,0,0), array(255,255,255) );  

If you don't want to subclass or change the tcpdf source just call the setHeaderData method and specify white line color.

$pdf->setHeaderData('',0,'','',array(0,0,0), array(255,255,255) );  
抽个烟儿 2024-12-20 03:28:48

通过扩展 TCPDF 类并修改页眉和页脚解决了问题。

class MYPDF extends TCPDF { 

    public function Header() 
    { 
        $image_file = K_PATH_IMAGES.'pdf-header.jpg'; 
        $this->Image($image_file, 160, 10, 40, '', 'JPG', '', 'T', false, 20, '', false, false, 0, false, false, false); 
        $this->SetFont('helvetica', 'B', 10); 
    } 

    public function Footer() 
    { 
        $this->SetY(-15); 
        $this->SetFont('helvetica', 'I', 8); 

    }
}

Problem solved by extends the TCPDF class and modify the header and footer.

class MYPDF extends TCPDF { 

    public function Header() 
    { 
        $image_file = K_PATH_IMAGES.'pdf-header.jpg'; 
        $this->Image($image_file, 160, 10, 40, '', 'JPG', '', 'T', false, 20, '', false, false, 0, false, false, false); 
        $this->SetFont('helvetica', 'B', 10); 
    } 

    public function Footer() 
    { 
        $this->SetY(-15); 
        $this->SetFont('helvetica', 'I', 8); 

    }
}
昨迟人 2024-12-20 03:28:48

tcpdf.php:

// print an ending header line
$this->SetLineStyle(array('width' => 0.25 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 255, 255)));

tcpdf.php:

// print an ending header line
$this->SetLineStyle(array('width' => 0.25 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 255, 255)));
梦里寻她 2024-12-20 03:28:48

如果此线程中发布的其他解决方案不起作用,我以这种方式解决:

TL;DR
在 Tcpdf 类 (tcpdf.php) 的 Footer() 函数中:
替换此行:

$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L'); // line 3527 in version 6.3.1
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R'); // line 3530 in version 6.3.1

使用此行

$this->Cell(0, 0, $pagenumtxt, 0, 0, 'L');
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 0, 0, 'R');

替代方式 1
在 Tcpdf 类 (tcpdf.php) 的 Footer() 函数中注释此行:
在我的文件(版本 6.3.1)中,它们被放置在第 3524 行,

//Print page number
if ($this->getRTL()) {
    $this->SetX($this->original_rMargin);
    $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
} else {
    $this->SetX($this->original_lMargin);
    $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
}

这将禁用页脚中页码的渲染,但至少会删除不需要的行。

替代方式2
如果这些方法不起作用,请在 tcpdf.php 文件中搜索以下字符串:

$this->SetLineStyle(array

您应该找到 3 次出现,将数组的“color”属性替换为值 [0,0,0] (或背景的 RGB 颜色),这应该会导致线条变成白色(或您设置的颜色)。
我使用这种方法通过放置自定义奇怪的颜色并查看正在渲染哪一个来解决问题所在。

说明
线条被渲染是因为线条中的

$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');

border 属性设置为“T”(顶部边框)。您可以通过将 border 属性设置为 0 来禁用边框(请参阅此处的文档, $边框参数)。
如果这不起作用,您可以完全禁用页码(以及边框)的渲染,或者您可以将边框设置为与实际背景相匹配的自定义颜色。

If the other solutions posted in this thread does not work, I solved in this way:

TL;DR
In Footer() function in Tcpdf class (tcpdf.php):
Replace this lines:

$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L'); // line 3527 in version 6.3.1
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R'); // line 3530 in version 6.3.1

With this lines

$this->Cell(0, 0, $pagenumtxt, 0, 0, 'L');
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 0, 0, 'R');

Alternative way 1
Comment this lines in Footer() function in Tcpdf class (tcpdf.php):
In my file (version 6.3.1) they were placed at line 3524

//Print page number
if ($this->getRTL()) {
    $this->SetX($this->original_rMargin);
    $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
} else {
    $this->SetX($this->original_lMargin);
    $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
}

This will disable the render of the page number in the footer but at least it removes the unwanted line.

Alternative way 2
If these methods does not work, search in the tcpdf.php file for this string:

$this->SetLineStyle(array

You should find 3 occurrences, replace the 'color' property of the array with the value [0,0,0] (or the rgb color of your background), this should cause the line to turn white (or the color you set).
I used this method to troubleshoot where the problem was by putting custom weird color and seeing which one was being rendered.

Explanation
The line is rendered because in the lines

$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');

The border property is set to 'T' (top border). You can disable the border by set the border property to 0 (see docs here, $border param).
If that doesn't work you can entirely disable the render of the page number (and thus the border), or you can set the border to a custom color that matches you actual background.

心如荒岛 2024-12-20 03:28:48

在 tcpdf 类的 Header() 函数中注释这一行:

$this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');

Comment this line in Header() function of tcpdf Class :

$this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文