src/Service/Generation/LabPdf.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3.  * To change this license header, choose License Headers in Project Properties.
  4.  * To change this template file, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. namespace App\Service\Generation;
  8. use Fpdf\Fpdf;
  9. class LabPdf {
  10.     function __construct($orientation 'L'$unit 'mm'$size 'A3') {
  11.         $this->filename uniqid();
  12.         $this->filepath __DIR__ '/../../../var/export/pdf/' $this->filename '.pdf';
  13.         $this->AliasNbPages();
  14.         return parent::__construct($orientation$unit$size);
  15.     }
  16.     public function TestOld() {
  17.         $pdf = new OldPDF();
  18.         $pdf->AliasNbPages();
  19.         $pdf->head2();
  20.         $pdf->JITOutput();
  21.     }
  22.     public function Test2() {
  23.         $pdf = new MinutesPdf();
  24. //        $pdf = new Minutes2Pdf();
  25.         $pdf->setContent();
  26.         $pdf->JITOutput();
  27.     }
  28.     public function Test3() {
  29. //        $pdf = new MinutesPdf();
  30.         $pdf = new ReportCardPdf();
  31.         $pdf->setContent();
  32.         $pdf->JITOutput();
  33.     }
  34.     public function Test4() {
  35.         $pdf = new MinutesPdf2022_1();
  36. //        $pdf = new Minutes2Pdf();
  37.         $pdf->setContent();
  38.         $pdf->JITOutput();
  39.     }
  40.     public function TestPdf() {
  41.         $pdf = new Fpdf('L''mm''A4');
  42. //Titres des colonnes
  43.         $header = array('Pays''Capitale''Superficie (km²)''Pop. (milliers)');
  44. //Chargement des données
  45.         $data = [['Cameroun''Yaoundé'4100025000]];
  46.         $pdf->SetFont('Arial'''4);
  47.         $pdf->AddPage();
  48.         $pdf $this->TotoTable($pdf$header$data);
  49. //        $pdf->AddPage();
  50. //        $pdf= $this->ImprovedTable($pdf, $header, $data);
  51. //        $pdf->AddPage();
  52. //        $pdf = $this->FancyTable($pdf, $header, $data);
  53. //        $pdf->Output();
  54. //        $pdf->Cell(260, 8, 'TONTON Blaise', 0, 1, 'C', 0);
  55. //        // Texte : 60 >largeur ligne, 8 >hauteur ligne. Premier 0 >pas de bordure, 1 >retour à la ligneensuite, C >centrer texte, 1> couleur de fond ok  
  56. //        $pdf->Cell(120, 18, 'TONTON Blaise', 0, 1, 'L', 0);
  57. ////        $pdf->Cell(60, 8, 'Blaise NOUTCHEU', 0, 1, 'C', 1);
  58. //        // Saut de ligne 10 mm
  59. //        $pdf->AddPage();
  60. ////        $pdf->Image($cd . $this->assetsManager->getUrl('img/ifpi_4.png'), 0, 0, $pdf->GetPageWidth(), $pdf->GetPageHeight());
  61. //        $pdf->Image($this->getImage('ifpi_4.png'), 0, 0, $pdf->GetPageWidth(), $pdf->GetPageHeight());
  62. //        $id = rand(0, 200);
  63. //        $path = './../../public/pdf/file' . $id . '.pdf';
  64.         $path 'export/pdf/' uniqid() . '.pdf';
  65. //        $cd = __DIR__;
  66. //        $path = $cd . '/../../../public/pdf/' . $client->getFilename();
  67. //        $path = $assetsManager->getUrl('pdf/file') . $id . '.pdf';
  68.         $pdf->Output('F'$path);
  69.     }
  70.     private function getImage($name) {
  71.         return 'img/' $name;
  72. //        $cd = __DIR__;
  73. //        return $cd . '/../../../public/img/'.$name;
  74.     }
  75. //Tableau simple
  76.     function TotoTable($pdf$header$data) {
  77.         //En-tête
  78.         foreach ($header as $col)
  79.             $pdf->Cell(107$col1);
  80.         $pdf->Ln();
  81.         //Données
  82.         foreach ($data as $row) {
  83.             foreach ($row as $col)
  84.                 $pdf->Cell(106$col1);
  85.             $pdf->Ln();
  86.         }
  87.         return $pdf;
  88.     }
  89. //Tableau simple
  90.     function BasicTable($pdf$header$data) {
  91.         //En-tête
  92.         foreach ($header as $col)
  93.             $pdf->Cell(407$col1);
  94.         $pdf->Ln();
  95.         //Données
  96.         foreach ($data as $row) {
  97.             foreach ($row as $col)
  98.                 $pdf->Cell(406$col1);
  99.             $pdf->Ln();
  100.         }
  101.         return $pdf;
  102.     }
  103. //Tableau amélioré
  104.     function ImprovedTable($pdf$header$data) {
  105.         //Largeurs des colonnes
  106.         $w = array(40354540);
  107.         //En-tête
  108.         for ($i 0$i count($header); $i++)
  109.             $pdf->Cell($w[$i], 7$header[$i], 10'C');
  110.         $pdf->Ln();
  111.         //Données
  112.         foreach ($data as $row) {
  113.             $pdf->Cell($w[0], 6$row[0], 'LR');
  114.             $pdf->Cell($w[1], 6$row[1], 'LR');
  115.             $pdf->Cell($w[2], 6number_format($row[2], 0','' '), 'LR'0'R');
  116.             $pdf->Cell($w[3], 6number_format($row[3], 0','' '), 'LR'0'R');
  117.             $pdf->Ln();
  118.         }
  119.         //Trait de terminaison
  120.         $pdf->Cell(array_sum($w), 0'''T');
  121.         return $pdf;
  122.     }
  123. //Tableau coloré
  124.     function FancyTable($pdf$header$data) {
  125.         //Couleurs, épaisseur du trait et police grasse
  126.         $pdf->SetFillColor(25500);
  127.         $pdf->SetTextColor(255);
  128.         $pdf->SetDrawColor(12800);
  129.         $pdf->SetLineWidth(.3);
  130.         $pdf->SetFont('''B');
  131.         //En-tête
  132.         $w = array(40354540);
  133.         for ($i 0$i count($header); $i++)
  134.             $pdf->Cell($w[$i], 7$header[$i], 10'C'1);
  135.         $pdf->Ln();
  136.         //Restauration des couleurs et de la police
  137.         $pdf->SetFillColor(224235255);
  138.         $pdf->SetTextColor(0);
  139.         $pdf->SetFont('');
  140.         //Données
  141.         $fill 0;
  142.         foreach ($data as $row) {
  143.             $pdf->Cell($w[0], 6$row[0], 'LR'0'L'$fill);
  144.             $pdf->Cell($w[1], 6$row[1], 'LR'0'L'$fill);
  145.             $pdf->Cell($w[2], 6number_format($row[2], 0','' '), 'LR'0'R'$fill);
  146.             $pdf->Cell($w[3], 6number_format($row[3], 0','' '), 'LR'0'R'$fill);
  147.             $pdf->Ln();
  148.             $fill = !$fill;
  149.         }
  150.         $pdf->Cell(array_sum($w), 0'''T');
  151.         return $pdf;
  152.     }
  153. }