1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| <?php
session_start();
echo $_SESSION['naam'];
echo $_SESSION['year'];
require('./fpdf.php');
class PDF extends FPDF
{
//En-tête
function Header()
{
//Logo
$this->Image('world.png',10,8,23,0,'','http://lau.jarry.free.fr/index.php/logiciel-libre/calculs-co2');
//Police Arial gras 15
$this->SetFont('Arial','B',15);
//Décalage à droite
$this->Cell(50);
//Titre
$this->Cell(100,10,'Profil Co2 de '.$_SESSION['naam'].'',1,0,'C');
$this->Cell($_SESSION['naam']);
//Saut de ligne
$this->Ln(10);
$this->Cell(10);
$this->SetFont('Arial','',15);
$this->Cell(0,10,'pour l année '.$_SESSION['year'].'',0,0,'C');
$this->Ln(20);
$this->SetFont('Arial','',11);
$this->MultiCell(0,8,'Ce profil est établi avec les facteurs de conversion CO2 du Bilan Carbone. Ils comprennent les énergies directes et indirectes.',0,1);
$this->Ln(10);
}
//Chargement des données
function LoadData($file)
{
//Lecture des lignes du fichier
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
//Tableau coloré
function FancyTable($header,$data)
{
//Couleurs, épaisseur du trait et police grasse
$this->SetFillColor(128,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//En-tête
$w=array(40,35);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
$this->Ln();
//Restauration des couleurs et de la police
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
//Données
$fill=false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w),0,'','T');
}
//Pied de page
function Footer()
{
//Positionnement à 1,5 cm du bas
$this->SetY(-15);
//Police Arial italique 8
$this->SetFont('Arial','I',8);
//Numéro de page
$this->Cell(0,10,'Module Joomla!1.5 - Profil CO2',0,0,'C');
}
}
$pdf=new PDF();
//Titres des colonnes
$header=array('Energie','Co2 (kg)');
//Chargement des données
$data=$pdf->LoadData('pays.txt');
$pdf->SetFont('Arial','',14);
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->SetTitle('Profil CO2');
$pdf->SetAuthor('LJ01');
$fpdf->write($_SESSION['naam']);
$pdf->Output();
?> |
Partager