php FPDF - 绘制一条以宽度为中心的线

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18715506/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:04:52  来源:igfitidea点击:

FPDF - Drawing a line that's centred across the width

phpfpdf

提问by BigJobbies

Im trying to produce a PDF document using the PHP FPDF library,

我正在尝试使用 PHP FPDF 库生成 PDF 文档,

Im trying to draw a line horizontal over the page which is indented the same amount both on the left and right sides.

我试图在页面上画一条水平线,该线在左侧和右侧缩进相同的数量。

Im having real difficulty trying to accomplish this.

我真的很难做到这一点。

My code is as follows, any help would be greatly appreciated.

我的代码如下,任何帮助将不胜感激。

$pdf = new FPDF( 'P', 'mm', 'A4' );

$pdf->AddPage();
$pdf->SetDisplayMode(real,'default');
$pdf->SetFillColor(0,0,0);
$pdf->SetFont('Arial','B',16);

$pdf->Image('logo.jpg',20,10,50,33.3);

$pdf->SetDrawColor(188,188,188);
$pdf->Line(20,45,150,45);

回答by gvee

Given a portrait, A4 page is 210mm wide, a simple bit of maths should help you resolve this:

给定一幅肖像,A4 页面的宽度为 210 毫米,简单的数学运算应该可以帮助您解决这个问题:

$pdf->Line(20, 45, 210-20, 45); // 20mm from each edge
$pdf->Line(50, 45, 210-50, 45); // 50mm from each edge

This is given that your declaration is as you stated in your original question:

这是因为您的声明如您在原始问题中所述:

$pdf = new FPDF( 'P', 'mm', 'A4' ); // A4, portrait, measurements in mm.

回答by Wasim Khan

Use the following -

使用以下 -

$pdf = new PDF('P','mm','A4');  //Set PDF as Potrait
$pdf->Ln(4);                    //Break
$pdf->Line(startpoint, 45, endpoint-50, 45);  //Set the line
$pdf->Ln(4); //Break