我为使用 TCPDF 创建的 PDF 创建了一个自定义标题。现在我想在页眉底部添加一条穿过页面但不知道怎么做的蓝线(大约 2px 宽度)?
问问题
41323 次
6 回答
10
我相信你会这样做:
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0));
$pdf->Line(5, 10, 80, 30, $style);
这是完整的例子
于 2011-05-01T06:23:23.513 回答
9
我找到了最简单的放线方法
$pdf->writeHTML("<hr>", true, false, false, false, '');
于 2016-02-28T14:34:59.230 回答
5
您还可以使用页轴:
$pdf->Line(5, $pdf->y, $pdf->w - 5, $pdf->y);
但是,如果您尝试呈现彩色<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;
于 2013-04-11T13:27:58.833 回答
0
重点是获取第二个点的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);
链接 TCPDF::getMargins()
http://www.tcpdf.org/doc/code/classTCPDF.html#ae9bd660bf5b5e00eea82f1168cc67b5b
TCPDF::getPageWidth()
http://www.tcpdf.org/doc/code/classTCPPDF.html#a510ab21d6a373934bcd3bd4683704b7e
玩得开心!
于 2014-05-17T05:43:51.533 回答
0
在当前位置画一条水平黑线:
$style = ['width' => 0.2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => [0, 0, 0]];
$this->pdf->SetLineStyle($style);
$this->pdf->Line(PDF_MARGIN_LEFT, $this->pdf->getY(), $this->pdf->getPageWidth()-PDF_MARGIN_LEFT, $this->pdf->getY());
$this->pdf->Ln();
于 2020-09-21T19:25:27.943 回答
0
只需添加一些 HTML :)
$html ='<hr>';
$pdf->writeHTML($html, true, false, true, false, '');
于 2016-08-26T00:54:13.863 回答