Générer un fichier PDF avec FPDF
Fermé
Luffy_87
Messages postés
10
Date d'inscription
mardi 15 septembre 2009
Statut
Membre
Dernière intervention
16 septembre 2010
-
5 oct. 2009 à 10:51
Luffy_87 Messages postés 10 Date d'inscription mardi 15 septembre 2009 Statut Membre Dernière intervention 16 septembre 2010 - 5 oct. 2009 à 14:47
Luffy_87 Messages postés 10 Date d'inscription mardi 15 septembre 2009 Statut Membre Dernière intervention 16 septembre 2010 - 5 oct. 2009 à 14:47
A voir également:
- Générer un fichier PDF avec FPDF
- Fichier rar - Guide
- Telecharger pdf - Guide
- Comment compresser un fichier pdf - Guide
- Fichier host - Guide
- Fichier iso - Guide
2 réponses
bissdebrazza
Messages postés
2064
Date d'inscription
vendredi 29 juin 2007
Statut
Contributeur
Dernière intervention
7 décembre 2017
713
5 oct. 2009 à 12:37
5 oct. 2009 à 12:37
Salut!
Je te donne le code que j'avais utilisé pour créer une liste des étudiants inscrit dans ma base (donc à modifier)
Je te donne le code que j'avais utilisé pour créer une liste des étudiants inscrit dans ma base (donc à modifier)
<?php
require('fpdf.php');
class PDF_MySQL_Table extends FPDF
{
var $ProcessingTable=false;
var $aCols=array();
var $TableX;
var $HeaderColor;
var $RowColors;
var $ColorIndex;
function Header()
{
//Imprime l'en-tête du tableau si nécessaire
if($this->ProcessingTable)
$this->TableHeader();
}
function TableHeader()
{
$this->SetFont('Arial','B',12);
$this->SetX($this->TableX);
$fill=!empty($this->HeaderColor);
if($fill)
$this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]);
foreach($this->aCols as $col)
$this->Cell($col['w'],6,$col['c'],1,0,'C',$fill);
$this->Ln();
}
function Row($data)
{
$this->SetX($this->TableX);
$ci=$this->ColorIndex;
$fill=!empty($this->RowColors[$ci]);
if($fill)
$this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
foreach($this->aCols as $col)
$this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill);
$this->Ln();
$this->ColorIndex=1-$ci;
}
function CalcWidths($width,$align)
{
//Calcule les largeurs des colonnes
$TableWidth=0;
foreach($this->aCols as $i=>$col)
{
$w=$col['w'];
if($w==-1)
$w=$width/count($this->aCols);
elseif(substr($w,-1)=='%')
$w=$w/100*$width;
$this->aCols[$i]['w']=$w;
$TableWidth+=$w;
}
//Calcule l'abscisse du tableau
if($align=='C')
$this->TableX=max(($this->w-$TableWidth)/2,0);
elseif($align=='R')
$this->TableX=max($this->w-$this->rMargin-$TableWidth,0);
else
$this->TableX=$this->lMargin;
}
function AddCol($field=-1,$width=-1,$caption='',$align='L')
{
//Ajoute une colonne au tableau
if($field==-1)
$field=count($this->aCols);
$this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);
}
function Table($query,$prop=array())
{
//Exécute la requête
$res=mysql_query($query) or die('Erreur: '.mysql_error()."<BR>Requête: $query");
//Ajoute toutes les colonnes si aucune n'a été définie
if(count($this->aCols)==0)
{
$nb=mysql_num_fields($res);
for($i=0;$i<$nb;$i++)
$this->AddCol();
}
//Détermine les noms des colonnes si non spécifiés
foreach($this->aCols as $i=>$col)
{
if($col['c']=='')
{
if(is_string($col['f']))
$this->aCols[$i]['c']=ucfirst($col['f']);
else
$this->aCols[$i]['c']=ucfirst(mysql_field_name($res,$col['f']));
}
}
//Traite les propriétés
if(!isset($prop['width']))
$prop['width']=0;
if($prop['width']==0)
$prop['width']=$this->w-$this->lMargin-$this->rMargin;
if(!isset($prop['align']))
$prop['align']='C';
if(!isset($prop['padding']))
$prop['padding']=$this->cMargin;
$cMargin=$this->cMargin;
$this->cMargin=$prop['padding'];
if(!isset($prop['HeaderColor']))
$prop['HeaderColor']=array();
$this->HeaderColor=$prop['HeaderColor'];
if(!isset($prop['color1']))
$prop['color1']=array();
if(!isset($prop['color2']))
$prop['color2']=array();
$this->RowColors=array($prop['color1'],$prop['color2']);
//Calcule les largeurs des colonnes
$this->CalcWidths($prop['width'],$prop['align']);
//Imprime l'en-tête
$this->TableHeader();
//Imprime les lignes
$this->SetFont('Arial','',11);
$this->ColorIndex=0;
$this->ProcessingTable=true;
while($row=mysql_fetch_array($res))
$this->Row($row);
$this->ProcessingTable=false;
$this->cMargin=$cMargin;
$this->aCols=array();
}
}
define('FPDF_FONTPATH','font/');
class PDF extends PDF_MySQL_Table
{
//en-tête de page
function Header()
{
//Titre et image
$this->Image('images/sup.jpg',32,3,200);
$this->Ln(25);
$this->SetFont('Times','B',16);
$this->Cell(0,6,'Liste des etudiants inscrits',0,1,'C');
$this->Ln(10);
//Imprime l'en-tête du tableau si nécessaire
parent::Header();
}
//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,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
//Connexion à la base
mysql_connect('localhost','root','');
mysql_select_db('ecole');
$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();
$pdf->AliasNbPages();
//tableau : définit 6 colonnes
$pdf->AddCol('cod_niv',15,'Niveau');
$pdf->AddCol('cod_fil',15,'Filiere');
$pdf->AddCol('nom',40,'Nom Etudiant');
$pdf->AddCol('prenom',40,'Prenom Etudiant');
$pdf->AddCol('phone',25,'Telephone');
$pdf->AddCol('mail',45,'E-mail');
$prop=array('HeaderColor'=>array(250,75,71),
'color1'=>array(157,157,255),
'color2'=>array(255,255,210),
'padding'=>1);
$pdf->Table('select cod_niv,cod_fil,nom,prenom,phone,mail from etudiant where statut="Actif" order by cod_niv',$prop);
$pdf->Output();
?>
si tu ne comprends pas quelque chose,tu peux revenir!
bissdebrazza
Messages postés
2064
Date d'inscription
vendredi 29 juin 2007
Statut
Contributeur
Dernière intervention
7 décembre 2017
713
5 oct. 2009 à 14:00
5 oct. 2009 à 14:00
essai de mettre le titre dans une variable,et ensuite là où est mon titre,tu fais appel à cette variable!
Luffy_87
Messages postés
10
Date d'inscription
mardi 15 septembre 2009
Statut
Membre
Dernière intervention
16 septembre 2010
5 oct. 2009 à 14:47
5 oct. 2009 à 14:47
Le problème est que le titre est définit avant la connexion à la base de donnée et que lorsque je met le code après il y a des erreurs
5 oct. 2009 à 13:57
J'ai testé le script mais il ne me permet pas de mettre mon titre en dynamique.
En fait ce qu'il faudrait c'est que le script affiche le nom d'un évènement en titre puis les participants de cette évènement, ensuite une autre page est créée avec comme titre le nom d'un deuxième évènement contenu dans ma base avec la liste des participants.