Line( x1, y1, x2, y2 );
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf -> Line(20, 20, 150, 200);
$pdf->Output();
?>
Output of above code is here.
<?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
<?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
<?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
<?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
$pdf->SetLineWidth(0.8);
$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
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.