Draw Lines in PDF document using FPDF

Line(x1,y1,x2,y2);
PDF line generation
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 -> w; // Width of Current Page
$height=$pdf -> h; // 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 -> w; // Width of Current Page
$height=$pdf -> h; // Height of Current Page
$edge=2; // Gap between line and border , change this value

$pdf->Line($edge, $edge,$width-$edge,$edge); // Horizontal line at top
$pdf->Line($edge, $height-$edge,$width-$edge,$height-$edge); // Horizontal line at bottom
$pdf->Line($edge, $edge,$edge,$height-$edge); // Vetical line at left 
$pdf->Line($width-$edge, $edge,$width-$edge,$height-$edge); // 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 -> w; // Width of Current Page
$height=$pdf -> h; // 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

Draw patterns of square boxes with reducing dimension across the page

<?Php
require('fpdf.php');
$pdf = new FPDF(); 
$pdf->AddPage();

$width=$pdf -> w; // Width of Current Page
$height=$pdf -> h; // Height of Current Page
$edge=2; // Gap between line and border 

for($edge=2;$edge<=$width/2; $edge+=2){
$pdf->Line($edge, $edge,$width-$edge,$edge); // Horizontal line at top
$pdf->Line($edge, $height-$edge,$width-$edge,$height-$edge); // Horizontal line at bottom
$pdf->Line($edge, $edge,$edge,$height-$edge); // Vetical line at left 
$pdf->Line($width-$edge, $edge,$width-$edge,$height-$edge); // Vetical 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 -> w; // Width of Current Page
$height=$pdf -> h; // Height of Current Page
$edge=2; // Gap between line and border 
$pdf->SetLineWidth(0.8);
$pdf->SetDrawColor(10,10,10);

for($edge=2;$edge<=$width/2; $edge+=5){
$pdf->SetDrawColor(10+(3*$edge),10+$edge,10+$edge);
$pdf->Line($edge, $edge,$width-$edge,$edge); // Horizontal line at top
$pdf->Line($edge, $height-$edge,$width-$edge,$height-$edge); // Horizontal line at bottom
$pdf->Line($edge, $edge,$edge,$height-$edge); // Vetical line at left 
$pdf->Line($width-$edge, $edge,$width-$edge,$height-$edge); // Vetical line at Right
}
$pdf->Output();
?>
Output is here


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-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer