php TCPDF 在页眉中跨页添加行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5846789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TCPDF add line across page in header
提问by Billy
I have created a custom header for my PDF created with TCPDF. Now I would like to add a blue line (about 2px width) that goes across the page at the bottom of the header but can't figure out how?
我为我用 TCPPDF 创建的 PDF 创建了一个自定义标题。现在我想在页眉底部添加一条穿过页面的蓝线(约 2px 宽),但不知道如何做?
回答by serby
I believe you do it like this:
我相信你是这样做的:
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0));
$pdf->Line(5, 10, 80, 30, $style);
Here is the full example
这是完整的例子
回答by ekerner
You can also use the page axis:
您还可以使用页面轴:
$pdf->Line(5, $pdf->y, $pdf->w - 5, $pdf->y);
However if you are trying to render a colored <hr>
html tag you will need to adjust the TCPDF::DrawColor
(this excerpt is from code that adds a graph bar to each row of a data report as per $twidth
and $lengthmm
):
但是,如果您尝试呈现彩色<hr>
html 标记,则需要调整TCPDF::DrawColor
(此摘录来自根据$twidth
和向数据报告的每一行添加图形条的代码$lengthmm
):
$htmlbar = '<hr style="width:' . $lengthmm . 'mm;">';
$oldDrawColor = $pdf->DrawColor;
$pdf->setDrawColor(121, 161, 46);
$pdf->MultiCell($twidth,'2',$htmlbar,0,'L',$fill,1,'','',true,0,true,false,4,'T',false);
$pdf->DrawColor = $oldDrawColor;
回答by Vinayak Shedgeri
I found the easiest way to put line
我找到了最简单的放置线的方法
$pdf->writeHTML("<hr>", true, false, false, false, '');
回答by Creeperstanson
Just add some HTML : )
只需添加一些 HTML :)
$html ='<hr>';
$pdf->writeHTML($html, true, false, true, false, '');
回答by Uwe Schmelzer
The point is to get the x value for the second point. This is how I do it:
重点是获取第二个点的 x 值。这就是我的做法:
$pageWidth = $pdf->getPageWidth(); // Get total page width, without margins
$pageMargins = $pdf->getMargins(); // Get all margins as array
$headerMargin = $pageMargins['header']; // Get the header margin
$px2 = $pageWidth - $headerMargin; // Compute x value for second point of line
$p1x = $this->getX();
$p1y = $this->getY();
$p2x = $px2;
$p2y = $p1y; // Use same y for a straight line
$style = array();
$this->Line($p1x, $p1y, $p2x, $p2y, $style);
Links
TCPDF::getMargins()
http://www.tcpdf.org/doc/code/classTCPDF.html#ae9bd660bf5b5e00eea82f1168cc67b5b
链接 TCPDF::getMargins()
http://www.tcpdf.org/doc/code/classTCPDF.html#ae9bd660bf5b5e00eea82f1168cc67b5b
TCPDF::getPageWidth()
http://www.tcpdf.org/doc/code/classTCPDF.html#a510ab21d6a373934bcd3bd4683704b7e
TCPDF::getPageWidth()
http://www.tcpdf.org/doc/code/classTCPDF.html#a510ab21d6a373934bcd3bd4683704b7e
Have fun!
玩得开心!