PHP 7 FPDF Example to Draw Polygon Graphics Shape in PDF Document Using Javascript

You are currently viewing PHP 7 FPDF Example to Draw Polygon Graphics Shape in PDF Document Using Javascript

PHP 7 FPDF Example to Draw Polygon Graphics Shape in PDF Document Using Javascript

<?php
require('fpdf.php');
 
class PDF_Polygon extends FPDF
{
 
function Polygon($points, $style='D')
{
    //Draw a polygon
    if($style=='F')
        $op = 'f';
    elseif($style=='FD' || $style=='DF')
        $op = 'b';
    else
        $op = 's';
 
    $h = $this->h;
    $k = $this->k;
 
    $points_string = '';
    for($i=0; $i<count($points); $i+=2){
        $points_string .= sprintf('%.2F %.2F', $points[$i]*$k, ($h-$points[$i+1])*$k);
        if($i==0)
            $points_string .= ' m ';
        else
            $points_string .= ' l ';
    }
    $this->_out($points_string . $op);
}
 
}
?>

<?php
require('polygon.php');
 
$pdf=new PDF_Polygon();
$pdf->AddPage();
$pdf->SetDrawColor(255,0,0);
$pdf->SetFillColor(0,0,255);
$pdf->SetLineWidth(4);
$pdf->Polygon(array(50,115,150,115,100,20),'FD');
$pdf->Output();
?>

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply