Draw Lines in PDF document using FPDF

Line(x1,y1,x2,y2);
PDF line generation

Line() method to draw lines using coordinates and by measuring page width and height

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.
Line drawn on PDF

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
Cross Lines drawn on PDF

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); // Vetical line at left 
$pdf->Line($width-$gap, $gap,$width-$gap,$height-$gap); // Vetical 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
Horizontal Lines with gap of 10 on PDF
Drawing patterns of lines on PDF document by FPDF class in PHP using color and width of the line

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); // Vetical line at left 
$pdf->Line($width-$gap, $gap,$width-$gap,$height-$gap); // Vetical line at Right
}
$pdf->Output();
?>
Output is here
Pattern Lines with gap of 10 on PDF

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); // Vetical line at left 
$pdf->Line($width-$gap, $gap,$width-$gap,$height-$gap); // Vetical line at Right
}
$pdf->Output();
?>
Output is here
Pattern of colour Lines with gap of 10 on PDF
MultiCell Cell()
Adding Image to PDF File
Subscribe to our YouTube Channel here

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer