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);
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(); ?>
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!
We can draw line in pdf documents by using Line() function in FPDF.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With