How to include one class inside another in PHP using FPDF

0

I hope you can support me, I am a beginner, I am working with PHP and FPDF, I currently have a document called index.php with the following code:

<?php
require_once(dirname(__FILE__) . '/Constantes.php');
require_once(RUTA_FPDF_PHP);
$pdf = new FPDF();
$pdf->AddFont('Calibri', '', 'Calibri.php');
$pdf->AddPage();
$pdf->SetFont('Calibri', '', 8);
$pdf->MultiCell(50, 5, utf8_decode("Hola mundo"), 1, 'C', FALSE);
$pdf->Output();
?>

and in another file called ellipse.php (I got it from the internet, draw ellipses and circles in PDF) the following code:

<?php

require_once 'Constantes.php';
require_once(RAIZ . '/PDF/fpdf/fpdf.php');

class PDF_Ellipse extends FPDF
{
function Circle($x, $y, $r, $style='D')
{
    $this->Ellipse($x, $y, $r, $r, $style);
}

function Ellipse($x, $y, $rx, $ry, $style='D')
{
    if($style=='F')
        $op='f';
    elseif($style=='FD' || $style=='DF')
        $op='B';
    else
        $op='S';
    $lx=4/3*(M_SQRT2-1)*$rx;
    $ly=4/3*(M_SQRT2-1)*$ry;
    $k=$this->k;
    $h=$this->h;
    $this->_out(sprintf('%.2F %.2F m %.2F %.2F %.2F %.2F %.2F %.2F c', 
        ($x+$rx)*$k, ($h-$y)*$k, 
        ($x+$rx)*$k, ($h-($y-$ly))*$k, 
        ($x+$lx)*$k, ($h-($y-$ry))*$k, 
        $x*$k, ($h-($y-$ry))*$k));
    $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', 
        ($x-$lx)*$k, ($h-($y-$ry))*$k, 
        ($x-$rx)*$k, ($h-($y-$ly))*$k, 
        ($x-$rx)*$k, ($h-$y)*$k));
    $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', 
        ($x-$rx)*$k, ($h-($y+$ly))*$k, 
        ($x-$lx)*$k, ($h-($y+$ry))*$k, 
        $x*$k, ($h-($y+$ry))*$k));
    $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c %s', 
        ($x+$lx)*$k, ($h-($y+$ry))*$k, 
        ($x+$rx)*$k, ($h-($y+$ly))*$k, 
        ($x+$rx)*$k, ($h-$y)*$k, 
        $op));
}
}
?>

I already tried the code of ellipse.php and it works perfectly, what I do not know is how to instantiate a new object of class PDF_Ellipse so that I can include it in my index.php, I need to make several circles in index.php, but I do not know how to start the class, nor how to include it in my index.php. I hope you can help me.

Thank you in advance to everyone.

P.D. I work with Windows 7 and PHP 7.

    
asked by Carlos Daniel Zárate Ramírez 20.06.2018 в 23:43
source

1 answer

0

Have you tried something like?

<?php
require_once(dirname(__FILE__) . '/Constantes.php');
require_once(RUTA_FPDF_PHP);
$pdf = new FPDF();
$pdf->AddFont('Calibri', '', 'Calibri.php');
$pdf->AddPage();
$pdf->SetFont('Calibri', '', 8);
$pdf->MultiCell(50, 5, utf8_decode("Hola mundo"), 1, 'C', FALSE);
$pdf->Ellipse(100,50,30,20);//Esta es la línea que dibujará tu elipse
$pdf->Output();
?>
    
answered by 20.06.2018 в 23:58