1

Bonjour,

je suis tout débutant.

J'ai déja des fichier php qui affiche des états. ces états sont des tableaux html mais le traitement de remplissage est fait avec du php.

Comment je peux utiliser html2pdf pour lui dire qu' il doit prendre le "content" généré par ces fichiers php ?

voici un exemple de fichier qui affiche un tableau. L'objectif est d'afficher ce tableau en pdf avec html2pdf.

<?php
function comptes_trimestre_cr($nature_compte,$annee_exercice)
{
?>
<html>
<head>
</head>

<body>
<p>
<table>
<caption><font size=4>Situation par trimestre des <?php echo $nature_compte;?> par CR</font></caption>
<?php
//Selectionner l'ensemble des CR qui sont dans Opeartions
$depassement_trimestre1=null;
$depassement_trimestre2=null;
$depassement_trimestre3=null;
$depassement_trimestre4=null;

$reliquat_trimestre1=null;
$reliquat_trimestre2=null;
$reliquat_trimestre3=null;
$reliquat_trimestre4=null;

$sql_liste_cr='select code_cr, nom_cr, localisation
from Cr group by code_cr, nom_cr, localisation';

$result_liste_cr=mysql_query($sql_liste_cr) or die ('Erreur SQL !'.$sql_liste_cr.'<br />'.mysql_error());

while($liste_cr=mysql_fetch_array($result_liste_cr))
{

$somme_1trimestre=montant_affecte_trimestre('mars',$liste_cr['code_cr'],$nature_compte);
$somme_2trimestre=montant_affecte_trimestre('juin',$liste_cr['code_cr'],$nature_compte);
$somme_3trimestre=montant_affecte_trimestre('sept',$liste_cr['code_cr'],$nature_compte);
$somme_4trimestre=montant_affecte_trimestre('dec',$liste_cr['code_cr'],$nature_compte);
$somme_realise_1trimes=montant_trimestre_cr('mars',$liste_cr['code_cr'],$nature_compte,$annee_exercice);
$somme_realise_2trimes=montant_trimestre_cr('juin',$liste_cr['code_cr'],$nature_compte,$annee_exercice);
$somme_realise_3trimes=montant_trimestre_cr('sept',$liste_cr['code_cr'],$nature_compte,$annee_exercice);
$somme_realise_4trimes=montant_trimestre_cr('dec',$liste_cr['code_cr'],$nature_compte,$annee_exercice);
if ($somme_1trimestre==null or $somme_1trimestre==0){
$taux_trimestre1=null;

}

if ($somme_2trimestre==null or $somme_2trimestre==0){

$taux_trimestre2=null;

}

if ($somme_3trimestre==null or $somme_3trimestre==0 ){

$taux_trimestre3=null;

}

if ($somme_4trimestre==null or $somme_4trimestre==0){

$taux_trimestre4=null;

}

if( $somme_realise_1trimes==null and $somme_1trimestre!=null)
{
$taux_trimestre1=number_format(0,2);

}

if ($somme_realise_2trimes==null and $somme_2trimestre!=null)
{
$taux_trimestre2=number_format(0,2);
}

if ($somme_realise_3trimes==null and $somme_3trimestre!=null)
{
$taux_trimestre3=number_format(0,2);
}

if ($somme_realise_4trimes==null and $somme_4trimestre!=null)
{
$taux_trimestre4=number_format(0,2);
}


if ($somme_1trimestre!=null and $somme_realise_1trimes!=null and $somme_1trimestre!=0)
{
$taux_trimestre1=($somme_realise_1trimes/$somme_1trimestre)*100;
/*$taux_trimestre1=number_format($taux_trimestre1,2);*/
}

if ($somme_realise_2trimes!=null and $somme_2trimestre!=null and $somme_2trimestre!=0)
{
$taux_trimestre2=($somme_realise_2trimes/$somme_2trimestre)*100;
/*$taux_trimestre2=number_format($taux_trimestre2,2);*/
}

if ($somme_realise_3trimes!=null and $somme_3trimestre!=null and $somme_3trimestre!=0)
{
$taux_trimestre3=($somme_realise_3trimes/$somme_3trimestre)*100;
/*$taux_trimestre3=number_format($taux_trimestre3,2);*/
}

if ($somme_realise_4trimes!=null and $somme_4trimestre!=null and $somme_4trimestre!=0)
{
$taux_trimestre4=($somme_realise_4trimes/$somme_4trimestre)*100;
/*$taux_trimestre4=number_format($taux_trimestre4,2);*/
}

if ($somme_realise_1trimes>$somme_1trimestre)
{
$depassement_trimestre1=$somme_realise_1trimes-$somme_1trimestre;
}
else
{
if ($somme_realise_1trimes<0)
{
$reliquat_trimestre1=$somme_1trimestre;
$taux_trimestre1=0;
}
else
{
$reliquat_trimestre1=$somme_1trimestre-$somme_realise_1trimes;
}
}


if ($somme_realise_2trimes>$somme_2trimestre)
{
$depassement_trimestre2=$somme_realise_2trimes-$somme_2trimestre;
}
else
{
if ($somme_realise_2trimes<0)
{
$reliquat_trimestre2=$somme_2trimestre;
$taux_trimestre2=0;
}
else
{
$reliquat_trimestre2=$somme_2trimestre-$somme_realise_2trimes;
}
}

if ($somme_realise_3trimes>$somme_3trimestre)
{
$depassement_trimestre3=$somme_realise_3trimes-$somme_3trimestre;
}
else
{
if ($somme_realise_3trimes<0)
{
$reliquat_trimestre3=$somme_3trimestre;
$taux_trimestre3=0;
}
else
{
$reliquat_trimestre3=$somme_3trimestre-$somme_realise_3trimes;
}
}

if ($somme_realise_4trimes>$somme_4trimestre)
{
$depassement_trimestre4=$somme_realise_4trimes-$somme_4trimestre;
}
else
{

if ($somme_realise_4trimes<0)
{
$reliquat_trimestre4=$somme_4trimestre;
$taux_trimestre4=0;
}
else
{
$reliquat_trimestre4=$somme_4trimestre-$somme_realise_4trimes;
}
}

?>

<tr>
<td colspan="6" style="text-align:left" ><center><span><b>Code_CR :</b><?php echo $liste_cr['code_cr'];?>              
<b>Nom CR :</b><?php echo $liste_cr['nom_cr'];?></span></center> </td>
</tr>
<tr>
<td></td>
<th>Budget trimestriels</th>
<th>Realisations</th>
<th>Taux</th>
<th>Reliquat</th>
<th>Dépassement</th>
</tr>
<tr>
<td>PREMIER TRIMESTRE</td>
<td style="text-align:right"><?php if ($somme_1trimestre!=null){ echo number_format($somme_1trimestre,2,'.',' ');}?></td>
<td style="text-align:right"><?php if ($somme_realise_1trimes!=null){echo number_format($somme_realise_1trimes,2,'.',' ');}?></td>
<td style="text-align:right"><?php if($taux_trimestre1!=null){ echo number_format($taux_trimestre1,2,'.',' ');}?>%</td>
<td style="text-align:right"><?php if($reliquat_trimestre1!=null){ echo number_format($reliquat_trimestre1,2,'.',' ');}?></td>
<td style="text-align:right"><?php if($depassement_trimestre1!=null){ echo number_format($depassement_trimestre1,2,'.',' ');}?></td>
</tr>

<tr>
<td>DEUXIEME TRIMESTRE</td>
<td style="text-align:right"><?php if($somme_2trimestre!=null){ echo number_format($somme_2trimestre,2,'.',' ');}?></td>
<td style="text-align:right"><?php if($somme_realise_2trimes!=null){ echo number_format($somme_realise_2trimes,2,'.',' ');}?></td>
<td style="text-align:right"><?php if($taux_trimestre2!=null){ echo number_format($taux_trimestre2,2,'.',' ');}?>%</td>
<td style="text-align:right"><?php if($reliquat_trimestre2!=null){ echo number_format($reliquat_trimestre2,2,'.',' ');}?></td>
<td style="text-align:right"><?php if($depassement_trimestre2!=null){ echo number_format($depassement_trimestre2,2,'.',' ');}?></td>
</tr>

<tr>
<td>TROISIEME TRIMESTRE</td>
<td style="text-align:right"><?php if($somme_3trimestre!=null){ echo number_format($somme_3trimestre,2,'.',' ');}?></td>
<td style="text-align:right"><?php if($somme_realise_3trimes!=null){ echo number_format($somme_realise_3trimes,2,'.',' ');}?></td>
<td style="text-align:right"><?php if($taux_trimestre3!=null){ echo number_format($taux_trimestre3,2,'.',' ');}?>%</td>
<td style="text-align:right"><?php if ($reliquat_trimestre3!=null){echo number_format($reliquat_trimestre3,2,'.',' ');}?></td>
<td style="text-align:right"><?php if($depassement_trimestre3!=null){ echo number_format($depassement_trimestre3,2,'.',' ');}?></td>
</tr>

<tr>
<td>QUATRIEME TRIMESTRE</td>
<td style="text-align:right"><?php if($somme_4trimestre!=null){ echo number_format($somme_4trimestre,2,'.',' ');}?></td>
<td style="text-align:right"><?php if($somme_realise_4trimes!=null){ echo number_format($somme_realise_4trimes,2,'.',' ');}?></td>
<td style="text-align:right"><?php if($taux_trimestre4!=null){ echo number_format($taux_trimestre4,2,'.',' ');}?>%</td>
<td style="text-align:right"><?php if ($reliquat_trimestre4!=null) {echo number_format($reliquat_trimestre4,2,'.',' ');}?></td>
<td style="text-align:right"><?php if($depassement_trimestre4!=null) { echo number_format($depassement_trimestre4,2,'.',' ');}?></td>
</tr>

<?php


} // Fin du boucle

//se déconnecter et libérer les ressources

mysql_free_result($result_liste_cr);

?>
</table>

</p>
</body>
</html>

<?php
}

?>

Merci de vos aides !

Cordialement

2

il suffit de suivre les exemples wink (l'exemple 7 par exemple)
Ancien pseudo : lolo

3

Bonjour,

Oui c'est bon il suffisait de se servir des : " ob_start()" .

Merci beaucoup.