Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

fpdf

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

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);
like image 780
BigJobbies Avatar asked Sep 10 '13 09:09

BigJobbies


People also ask

How do you make a horizontal Line in FPDF?

Draw horizontal lines at a gap of 10 throughout the page php'); $pdf = new FPDF(); $pdf->AddPage(); $width=$pdf->GetPageWidth(); // Width of Current Page $height=$pdf->GetPageHeight(); // Height of Current Page $i=0; for($i=0;$i<=$height;$i +=10){ $pdf -> Line(0, $i, $pdf -> w, $i); } $pdf->Output(); ?>

How do you center a table in FPDF?

To center things on the page use SetLeftMargin to half of the difference between the page width, 210, and the total width of your columns, 153 which comes out to 28. Right after you create the instance of FPDF set the margin before starting a new page. Yes sir you right!

How do I make a Line in FPDF?

We can draw line in pdf documents by using Line() function in FPDF.


1 Answers

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

$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.
like image 170
gvee Avatar answered Oct 18 '22 02:10

gvee