2011-05-01 49 views
3

我为使用TCPDF创建的PDF创建了自定义标题。现在我想添加一个蓝色的线(大约2px宽),它贯穿页眉底部的页面,但不知道如何?TCPDF在标题页中添加行

回答

10

我相信你做这样的:

$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)); 

$pdf->Line(5, 10, 80, 30, $style); 

下面是完整的例子

http://www.tcpdf.org/examples/example_012.phps

+0

@PabliSerbo - 感谢您的例子我现在明白了。但是,如何获得标题的宽度来设置线宽? – Billy 2011-05-01 06:57:34

3

您还可以使用页面轴:

$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; 
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/classTCPDF.html#a510ab21d6a373934bcd3bd4683704b7e

玩得开心!

2

我发现最简单的方法把线

$pdf->writeHTML("<hr>", true, false, false, false, ''); 
0

只需添加一些HTML:)

$html ='<hr>'; 
$pdf->writeHTML($html, true, false, true, false, '');