FPDF MultiCell + BDD SQL

Fermé
Lord_Onance Messages postés 61 Date d'inscription jeudi 4 juin 2015 Statut Membre Dernière intervention 3 juillet 2015 - 12 juin 2015 à 14:23
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 - 18 juin 2015 à 10:28
Bonjour à tous,
je dois créer un PDF avec la classe FPDF à partir d'une BDD.

Pour le moment j'utilise la fonction Cell mais lorsque mon texte est long, il dépasse sur les autres cellules, j'ai donc décidé de me mettre aux MultiCell.
Le soucis étant que je n'arrive pas DU TOUT à appliquer le MultiCell avec ma requête..

Code :

<?php
require('connexion.php');
require ('fpdf.php');

class PDF extends FPDF
{
var $col = 0;
var $y0;
function Header (){

// Logo
$this->Image('logo.png',10,6,30);
// Police Arial gras 15
$this->SetFont('Arial','B',15);
// Décalage à droite
$this->Cell(95);
// Titre
$this->Cell(10,20,'Récapitulatif des prestations','C');
// Saut de ligne
$this->Ln(20);
}
function Footer()
{
// Pied de page
$this->SetY(-15);
$this->SetFont('Arial','I',8);
$this->SetTextColor(128);
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
function SetCol($col)
{
// Positionnement sur une colonne
$this->col = $col;
$x = 10+$col*65;
$this->SetLeftMargin($x);
$this->SetX($x);
}

function AcceptPageBreak()
{
// Méthode autorisant ou non le saut de page automatique
if($this->col<2)
{
// Passage à la colonne suivante
$this->SetCol($this->col+1);
// Ordonnée en haut
$this->SetY($this->y0);
// On reste sur la page
return false;
}
else
{
// Retour en première colonne
$this->SetCol(0);
// Saut de page
return true;
}
}
function Tableau($header,$data)
{
//Couleurs, épaisseur du trait et police BOLD
$this->SetFillColor(150,180,255); //fond des entetes de colonnes
$this->SetTextColor(0); //couleur du texte des entetes des colonnes
$this->SetDrawColor(0); // couleur des bordures
$this->SetLineWidth(.2); //epaisseur des traits
$this->SetFont('','B');

//En-tête
$w=array(7,30,50,15,15,25,30,7,15,15,15,15,16,16,20);
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); //couleur du fond des cases
$this->SetTextColor(0); //couleur du texte des cases
$this->SetFont('');

//Données
$fill=true;
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->Cell($w[2],6,$row[2],'LR',0,'L',$fill);
$this->Cell($w[3],6,$row[3],'LR',0,'L',$fill);
$this->Cell($w[4],6,$row[4],'LR',0,'L',$fill);
$this->Cell($w[5],6,$row[5],'LR',0,'L',$fill);
$this->Cell($w[6],6,$row[6],'LR',0,'L',$fill);
$this->Cell($w[7],6,$row[7],'LR',0,'L',$fill);
$this->Cell($w[8],6,$row[8],'LR',0,'L',$fill);
$this->Cell($w[9],6,$row[9],'LR',0,'L',$fill);
$this->Cell($w[10],6,$row[10],'LR',0,'L',$fill);
$this->Cell($w[11],6,$row[11],'LR',0,'L',$fill);
$this->Cell($w[12],6,$row[12],'LR',0,'L',$fill);
$this->Cell($w[13],6,$row[13],'LR',0,'L',$fill);
$this->Cell($w[14],6,$row[14],'LR',0,'L',$fill);
$this->Ln();
$fill=!$fill;
}

$this->Cell(array_sum($w),0,'','T');
}
}


$data = array();
//Requete SQL, pour la classe imprimer on change le format DATE_TIME vers DATE avec 'CAST'
$sql = $pdo->query ('SELECT event_id, event_titre, event_description, CAST( event_debut AS DATE ), CAST(event_finTH as DATE), event_nomclient, event_lieu, event_type, event_ref, event_numero, event_commercial, CAST(event_dateDtransp as DATE), event_nbembauche, event_nbcuisinier, event_heureArrivee FROM table_evenements');
//Boucle sur les resultats
while($col = $sql->fetch())
{
array($col);
$data[] = $col;
}

$sql->closeCursor();

//Creation nouveau pdf L = Paysage, P = Portrait
$pdf=new PDF('L');

//Titres des colonnes
$header=array('Id','Titre','Description','Début','Fin Th.','Client','Lieu','Type','Ref.','Numéro','Commercial','Transp Deb','NB Serveur','Nb Cuisinier','Arrivée');

//Tableau
$pdf->SetFont('Arial','',7);
$titre = 'Recapitulatif Prestation';
$pdf->SetTitle($titre);
$pdf->SetMargins(2,30);
$pdf->AddPage();
$pdf->Tableau($header,$data);
$pdf->Output('Recapitulatif_Prestations_'.date("Y_m_d").'.pdf','I');
?>

Je voudrais donc remplacer les Cellules normales par du MultiCell.
Je vous remercie d'avance, et soyez indulgents, je suis un grand débutant ;) !

1 réponse

pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 744
18 juin 2015 à 10:28
Bonjour,

Si votre problème a été résolu, merci de nous indiquer comment. Cela pourrait servir à d'autres internautes...
0