PHP
PDF Cell()
Line ( x1 , y1 , x2 , y2 );
Line() method to draw lines using coordinates and by measuring page width and height
VIDEO
Here is a simple code to draw line
<?php
require ('fpdf.php' );
$pdf = new FPDF ();
$pdf ->AddPage ();
$pdf -> Line (20 , 20 , 150 , 200 );
$pdf ->Output ();
?>
Output of above code is here.
Draw a cross X using full length of page
<?php
require ('fpdf.php' );
$pdf = new FPDF ();
$pdf ->AddPage ();
$width = $pdf ->GetPageWidth (); // Width of Current Page
$height = $pdf ->GetPageHeight (); // Height of Current Page
$pdf ->Line (0 , 0 , $width , $height ); // Line one Cross
$pdf ->Line ($width , 0 , 0 , $height ); // Line two Cross
$pdf ->Output ();
?>
Output is here
Draw border at a gap of 2 across the page
<?php
require ('fpdf.php' );
$pdf = new FPDF ();
$pdf ->AddPage ();
$width = $pdf ->GetPageWidth (); // Width of Current Page
$height = $pdf ->GetPageHeight (); // Height of Current Page
$gap = 2 ; // Gap between line and border, change this value
$pdf ->Line ($gap , $gap , $width - $gap , $gap ); // Horizontal line at top
$pdf ->Line ($gap , $height - $gap , $width - $gap , $height - $gap ); // Horizontal line at bottom
$pdf ->Line ($gap , $gap , $gap , $height - $gap ); // Vertical line at left
$pdf ->Line ($width - $gap , $gap , $width - $gap , $height - $gap ); // Vertical line at right
$pdf ->Output ();
?>
Output is here
Draw horizontal lines at a gap of 10 throughout the page
<?php
require ('fpdf.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 ();
?>
Output is here
Drawing patterns of lines on PDF document by FPDF class in PHP using color and width of the line
VIDEO
Draw patterns of square boxes with reducing dimension across the page
<?php
require ('fpdf.php' );
$pdf = new FPDF ();
$pdf ->AddPage ();
$width = $pdf ->GetPageWidth (); // Width of Current Page
$height = $pdf ->GetPageHeight (); // Height of Current Page
$gap = 2 ; // Gap between line and border
for ($gap = 2 ; $gap <= $width / 2 ; $gap += 2 ) {
$pdf ->Line ($gap , $gap , $width - $gap , $gap ); // Horizontal line at top
$pdf ->Line ($gap , $height - $gap , $width - $gap , $height - $gap ); // Horizontal line at bottom
$pdf ->Line ($gap , $gap , $gap , $height - $gap ); // Vertical line at left
$pdf ->Line ($width - $gap , $gap , $width - $gap , $height - $gap ); // Vertical line at right
}
$pdf ->Output ();
?>
Output is here
SetLineWidth(float width)
We can change line width ( default value is 0.2 )
$pdf ->SetLineWidth (0.8 );
SetDrawColor(R,G,B) to change line color
$pdf ->SetDrawColor (10 , 10 , 10 );
We can change our patern drawing code like this
<?php
require ('fpdf.php' );
$pdf = new FPDF ();
$pdf ->AddPage ();
$width = $pdf ->GetPageWidth (); // Width of Current Page
$height = $pdf ->GetPageHeight (); // Height of Current Page
$gap = 2 ; // Gap between line and border
$pdf ->SetLineWidth (0.8 );
$pdf ->SetDrawColor (10 , 10 , 10 );
for ($gap = 2 ; $gap <= $width / 2 ; $gap += 5 ) {
$pdf ->SetDrawColor (10 + (3 * $gap ), 10 + $gap , 10 + $gap );
$pdf ->Line ($gap , $gap , $width - $gap , $gap ); // Horizontal line at top
$pdf ->Line ($gap , $height - $gap , $width - $gap , $height - $gap ); // Horizontal line at bottom
$pdf ->Line ($gap , $gap , $gap , $height - $gap ); // Vertical line at left
$pdf ->Line ($width - $gap , $gap , $width - $gap , $height - $gap ); // Vertical line at right
}
$pdf ->Output ();
?>
Output is here
← MultiCell
Cell() →
Adding Image to PDF File →
← Subscribe to our YouTube Channel here