<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Service\Generation;
use Fpdf\Fpdf;
class LabPdf {
function __construct($orientation = 'L', $unit = 'mm', $size = 'A3') {
$this->filename = uniqid();
$this->filepath = __DIR__ . '/../../../var/export/pdf/' . $this->filename . '.pdf';
$this->AliasNbPages();
return parent::__construct($orientation, $unit, $size);
}
public function TestOld() {
$pdf = new OldPDF();
$pdf->AliasNbPages();
$pdf->head2();
$pdf->JITOutput();
}
public function Test2() {
$pdf = new MinutesPdf();
// $pdf = new Minutes2Pdf();
$pdf->setContent();
$pdf->JITOutput();
}
public function Test3() {
// $pdf = new MinutesPdf();
$pdf = new ReportCardPdf();
$pdf->setContent();
$pdf->JITOutput();
}
public function Test4() {
$pdf = new MinutesPdf2022_1();
// $pdf = new Minutes2Pdf();
$pdf->setContent();
$pdf->JITOutput();
}
public function TestPdf() {
$pdf = new Fpdf('L', 'mm', 'A4');
//Titres des colonnes
$header = array('Pays', 'Capitale', 'Superficie (km²)', 'Pop. (milliers)');
//Chargement des données
$data = [['Cameroun', 'Yaoundé', 41000, 25000]];
$pdf->SetFont('Arial', '', 4);
$pdf->AddPage();
$pdf = $this->TotoTable($pdf, $header, $data);
// $pdf->AddPage();
// $pdf= $this->ImprovedTable($pdf, $header, $data);
// $pdf->AddPage();
// $pdf = $this->FancyTable($pdf, $header, $data);
// $pdf->Output();
// $pdf->Cell(260, 8, 'TONTON Blaise', 0, 1, 'C', 0);
// // Texte : 60 >largeur ligne, 8 >hauteur ligne. Premier 0 >pas de bordure, 1 >retour à la ligneensuite, C >centrer texte, 1> couleur de fond ok
// $pdf->Cell(120, 18, 'TONTON Blaise', 0, 1, 'L', 0);
//// $pdf->Cell(60, 8, 'Blaise NOUTCHEU', 0, 1, 'C', 1);
// // Saut de ligne 10 mm
// $pdf->AddPage();
//// $pdf->Image($cd . $this->assetsManager->getUrl('img/ifpi_4.png'), 0, 0, $pdf->GetPageWidth(), $pdf->GetPageHeight());
// $pdf->Image($this->getImage('ifpi_4.png'), 0, 0, $pdf->GetPageWidth(), $pdf->GetPageHeight());
// $id = rand(0, 200);
// $path = './../../public/pdf/file' . $id . '.pdf';
$path = 'export/pdf/' . uniqid() . '.pdf';
// $cd = __DIR__;
// $path = $cd . '/../../../public/pdf/' . $client->getFilename();
// $path = $assetsManager->getUrl('pdf/file') . $id . '.pdf';
$pdf->Output('F', $path);
}
private function getImage($name) {
return 'img/' . $name;
// $cd = __DIR__;
// return $cd . '/../../../public/img/'.$name;
}
//Tableau simple
function TotoTable($pdf, $header, $data) {
//En-tête
foreach ($header as $col)
$pdf->Cell(10, 7, $col, 1);
$pdf->Ln();
//Données
foreach ($data as $row) {
foreach ($row as $col)
$pdf->Cell(10, 6, $col, 1);
$pdf->Ln();
}
return $pdf;
}
//Tableau simple
function BasicTable($pdf, $header, $data) {
//En-tête
foreach ($header as $col)
$pdf->Cell(40, 7, $col, 1);
$pdf->Ln();
//Données
foreach ($data as $row) {
foreach ($row as $col)
$pdf->Cell(40, 6, $col, 1);
$pdf->Ln();
}
return $pdf;
}
//Tableau amélioré
function ImprovedTable($pdf, $header, $data) {
//Largeurs des colonnes
$w = array(40, 35, 45, 40);
//En-tête
for ($i = 0; $i < count($header); $i++)
$pdf->Cell($w[$i], 7, $header[$i], 1, 0, 'C');
$pdf->Ln();
//Données
foreach ($data as $row) {
$pdf->Cell($w[0], 6, $row[0], 'LR');
$pdf->Cell($w[1], 6, $row[1], 'LR');
$pdf->Cell($w[2], 6, number_format($row[2], 0, ',', ' '), 'LR', 0, 'R');
$pdf->Cell($w[3], 6, number_format($row[3], 0, ',', ' '), 'LR', 0, 'R');
$pdf->Ln();
}
//Trait de terminaison
$pdf->Cell(array_sum($w), 0, '', 'T');
return $pdf;
}
//Tableau coloré
function FancyTable($pdf, $header, $data) {
//Couleurs, épaisseur du trait et police grasse
$pdf->SetFillColor(255, 0, 0);
$pdf->SetTextColor(255);
$pdf->SetDrawColor(128, 0, 0);
$pdf->SetLineWidth(.3);
$pdf->SetFont('', 'B');
//En-tête
$w = array(40, 35, 45, 40);
for ($i = 0; $i < count($header); $i++)
$pdf->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
$pdf->Ln();
//Restauration des couleurs et de la police
$pdf->SetFillColor(224, 235, 255);
$pdf->SetTextColor(0);
$pdf->SetFont('');
//Données
$fill = 0;
foreach ($data as $row) {
$pdf->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
$pdf->Cell($w[1], 6, $row[1], 'LR', 0, 'L', $fill);
$pdf->Cell($w[2], 6, number_format($row[2], 0, ',', ' '), 'LR', 0, 'R', $fill);
$pdf->Cell($w[3], 6, number_format($row[3], 0, ',', ' '), 'LR', 0, 'R', $fill);
$pdf->Ln();
$fill = !$fill;
}
$pdf->Cell(array_sum($w), 0, '', 'T');
return $pdf;
}
}