par
piotrowski-s » 08 juin 2012, 10:44
Bonjpour à tous, j'ai un soucis avec la librairie html2pdf,
en fait j'ai besoin de générer une page et de la convertir en pdf, je fais donc ma page classiqeu avec mes requêtes php mais la ça bloque en fait, j'ai tout ça:
<p align="center">
<?php
if (isset($_GET['tache']))
{
$date1= date('Y-m-d',strtotime($_GET['date1']));
$date2= date('Y-m-d',strtotime($_GET['date2']));
$sql = "SELECT * FROM agenda WHERE action LIKE '%".mysql_real_escape_string($_GET['tache'])."%' AND date_action > '".$date1."' AND date_action < '".$date2."' AND date_validation='0000-00-00'";
$qry = mysql_query($sql) or die(__LINE__.mysql_error().$sql);
$num_rows = mysql_num_rows($qry);
$lignes= $num_rows;
$get_date = function($data_jours) {
$today = new DateTime();
$today->setTime(0, 0);
$jours = (isset($_POST['jours']) && ctype_digit($_POST['jours'])) ? $_POST['jours'] : 0;
if (isset($_POST['submit']) && ($_POST['submit'] === 'moins')) {
$jours = -$jours;
}
$nb = $data_jours + $jours;
$func = ($nb < 0) ? 'sub' : 'add';
$interval = new DateInterval("P{$nb}D");
return $today->$func($interval)->format('d-m-Y');
};
$i = -1; // index des enregistrements
?><img src="images/agenda.png">
</p>
<table border="0" width="100%"><tr><td nowrap>Du <?php echo $_GET['date1'] ; ?> Au <?php echo $_GET['date2'] ; ?>, Critères : <?php echo $_GET['tache'] ; ?></td><td nowrap align="right">édité le <?php echo date('d-m-Y') ; ?></td></tr></table>
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000" style="border:thin" rules="cols, rows" >
<THEAD>
<tr><th width="auto" nowrap><strong>CLIENT</strong></th>
<th width="auto" nowrap><strong>N° DE DOSSIER</strong></th>
<th width="auto" nowrap><strong>NOM</strong></th>
<th width="auto" nowrap><strong>TEL</strong></th>
<th width="auto" nowrap><strong>DATE </strong></th>
<th width="auto" nowrap><strong>TRAITEMENT</strong></th>
<th width="auto" nowrap><strong>DESCRIPTION</strong></th>
<th width="auto" nowrap><strong>RESTANT DU</strong></th>
</tr>
</THEAD>
<?php while($row = mysql_fetch_assoc($qry)): ?>
<tbody>
<tr>
<td nowrap><?php echo strtoupper($row['code_client']) ; ?></td>
<td nowrap><?php echo strtoupper($row['n_doss']) ; ?></td> <td nowrap><?php $sql2 = "SELECT * FROM CLIENT WHERE n_doss='".$row['n_doss']."' GROUP BY n_doss";
$qry2 = mysql_query($sql2) or die(__LINE__.mysql_error().$sql2);
while($row2 = mysql_fetch_assoc($qry2)):
if (!empty($row2['raison_sociale'])) { echo strtoupper($row2['raison_sociale']) ; } else { echo strtoupper($row2['nom']) ; }
?></td>
<td nowrap><?php echo chunk_split($row2['tel'], 2, "."); endwhile ?></td><td nowrap><?php
$datetime1 = new DateTime("now");
$datetime2 = new DateTime($row['date_action']);
$interval = date_diff($datetime1, $datetime2);
echo $get_date("".$interval->format('%a'));
?></td>
<td nowrap><?php echo strtoupper($row['action']); ?></td>
<td nowrap><?php echo strtoupper($row['description']); ?>
</td>
<td nowrap><?php $sql7 = "SELECT SUM(montant) as montant FROM factures WHERE n_doss='".mysql_real_escape_string($row['n_doss'])."'";
$req7 = mysql_query ($sql7) or die ('Erreur SQL !<br>'.$sql7.'<br>'.mysql_error ());
while($data9 = mysql_fetch_assoc ($req7))
{ $pp=$data9['montant'] ;
if (empty($data9['montant'])) {
echo '0,00'; }
else {
$pp = $data9['montant'] ; $nbr2 = $pp;
// Notation française
$pp = number_format($nbr2, 2, ',', ' ');
// 1 234,56
}
} ?><?php
$sql = "select * from factures where n_doss='".mysql_real_escape_string($row['n_doss'])."' GROUP BY n_doss";
$query = mysql_query($sql);
while ($data=mysql_fetch_assoc($query))
{
$principal = $data['montant'];
$echeance = $data['date_echue'];
$day= date('y-m-d');
$s = strtotime($day)-strtotime($echeance);
$d = intval($s/86400)+1;
$i = (0.0006);
$tx= $principal*($i/360)*$d;
$i2= number_format($tx, 2, ',', ' ');
}
?><?php $sql5 = "SELECT SUM(montant) as montant FROM versements WHERE n_doss='".mysql_real_escape_string($row['n_doss'])."' AND etat ='3'";
$req5 = mysql_query ($sql5) or die ('Erreur SQL !<br>'.$sql5.'<br>'.mysql_error ());
while($data10 = mysql_fetch_assoc ($req5))
{ $nbr4=$data10['montant'] ;
// Notation française
$rgt2 = $nbr4;
$rgt = number_format($nbr4, 2, ',', ' ');
// 1 234,56
}
$versement = $rgt ;
?><?php
$sql253 = "SELECT * FROM `liasses` WHERE n_doss='".mysql_real_escape_string($row['n_doss'])."'";
$req117 = mysql_query ($sql253) or die ('Erreur SQL !<br>'.$sql253.'<br>'.mysql_error ());
$num_rows = mysql_num_rows($req117) ;
if ($num_rows =='0')
{
$sql17 = "SELECT SUM(`factures`.`montant`) AS montant FROM `factures` WHERE `factures`.`n_doss`='".mysql_real_escape_string($row['n_doss'])."'";
}
else
{
$sql17 = "SELECT SUM(`factures`.`montant`) + SUM(`liasses`.`montant`) AS montant FROM `factures` INNER JOIN `liasses` ON `factures`.`n_doss`=`liasses`.`n_doss` WHERE `factures`.`n_doss`='".mysql_real_escape_string($row['n_doss'])."'";
}
$req17 = mysql_query ($sql17) or die ('Erreur SQL !<br>'.$sql17.'<br>'.mysql_error ());
while($data119 = mysql_fetch_assoc ($req17))
{
$sd1 = number_format(($data119['montant']+ $tx-$nbr4) , 2, ',', ' ');
$principal2= $data119['montant'] ;
}
$principal3=$principal2;
echo $sd1;
?>
€</td>
</tr><?php endwhile; ?> <?php }?>
</tbody>
<tfoot>
<!--rangées du tableau-->
</tfoot>
</table>
<p align="right"><?php echo $lignes ; ?> Actions à traiter.
</body>
ceci est le contenu de ma page et en fait ça me génère un agenda en fonction de certains critères sous la forme d'un tableau.
de l'autre côté j'ai ça qui me permet de générer le pdf grâce à la librairie:
<?php
$content = "
<page>
<h1>Exemple d'utilisation</h1>
<br>
Ceci est un <b>exemple d'utilisation</b>
de <a href='http://html2pdf.fr/'>HTML2PDF</a>.<br>
</page>";
require_once(dirname(__FILE__).'/html2pdf.class.php');
$html2pdf = new HTML2PDF('L','A4','fr');
$html2pdf->WriteHTML($content);
$html2pdf->Output('exemple.pdf');
?>
Le soucis c'est que je ne sais pas comment récupérer tout mon contenu générer avant en php dans une seule variable $content, j'ai bien essayé en tout concaténant, etc, mais j'ai pleins d'erreurs et ça ne fonctionne pas.
Par avance merci pour votre aide.
Bonjpour à tous, j'ai un soucis avec la librairie html2pdf,
en fait j'ai besoin de générer une page et de la convertir en pdf, je fais donc ma page classiqeu avec mes requêtes php mais la ça bloque en fait, j'ai tout ça:
[php]<p align="center">
<?php
if (isset($_GET['tache']))
{
$date1= date('Y-m-d',strtotime($_GET['date1']));
$date2= date('Y-m-d',strtotime($_GET['date2']));
$sql = "SELECT * FROM agenda WHERE action LIKE '%".mysql_real_escape_string($_GET['tache'])."%' AND date_action > '".$date1."' AND date_action < '".$date2."' AND date_validation='0000-00-00'";
$qry = mysql_query($sql) or die(__LINE__.mysql_error().$sql);
$num_rows = mysql_num_rows($qry);
$lignes= $num_rows;
$get_date = function($data_jours) {
$today = new DateTime();
$today->setTime(0, 0);
$jours = (isset($_POST['jours']) && ctype_digit($_POST['jours'])) ? $_POST['jours'] : 0;
if (isset($_POST['submit']) && ($_POST['submit'] === 'moins')) {
$jours = -$jours;
}
$nb = $data_jours + $jours;
$func = ($nb < 0) ? 'sub' : 'add';
$interval = new DateInterval("P{$nb}D");
return $today->$func($interval)->format('d-m-Y');
};
$i = -1; // index des enregistrements
?><img src="images/agenda.png">
</p>
<table border="0" width="100%"><tr><td nowrap>Du <?php echo $_GET['date1'] ; ?> Au <?php echo $_GET['date2'] ; ?>, Critères : <?php echo $_GET['tache'] ; ?></td><td nowrap align="right">édité le <?php echo date('d-m-Y') ; ?></td></tr></table>
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000" style="border:thin" rules="cols, rows" >
<THEAD>
<tr><th width="auto" nowrap><strong>CLIENT</strong></th>
<th width="auto" nowrap><strong>N° DE DOSSIER</strong></th>
<th width="auto" nowrap><strong>NOM</strong></th>
<th width="auto" nowrap><strong>TEL</strong></th>
<th width="auto" nowrap><strong>DATE </strong></th>
<th width="auto" nowrap><strong>TRAITEMENT</strong></th>
<th width="auto" nowrap><strong>DESCRIPTION</strong></th>
<th width="auto" nowrap><strong>RESTANT DU</strong></th>
</tr>
</THEAD>
<?php while($row = mysql_fetch_assoc($qry)): ?>
<tbody>
<tr>
<td nowrap><?php echo strtoupper($row['code_client']) ; ?></td>
<td nowrap><?php echo strtoupper($row['n_doss']) ; ?></td> <td nowrap><?php $sql2 = "SELECT * FROM CLIENT WHERE n_doss='".$row['n_doss']."' GROUP BY n_doss";
$qry2 = mysql_query($sql2) or die(__LINE__.mysql_error().$sql2);
while($row2 = mysql_fetch_assoc($qry2)):
if (!empty($row2['raison_sociale'])) { echo strtoupper($row2['raison_sociale']) ; } else { echo strtoupper($row2['nom']) ; }
?></td>
<td nowrap><?php echo chunk_split($row2['tel'], 2, "."); endwhile ?></td><td nowrap><?php
$datetime1 = new DateTime("now");
$datetime2 = new DateTime($row['date_action']);
$interval = date_diff($datetime1, $datetime2);
echo $get_date("".$interval->format('%a'));
?></td>
<td nowrap><?php echo strtoupper($row['action']); ?></td>
<td nowrap><?php echo strtoupper($row['description']); ?>
</td>
<td nowrap><?php $sql7 = "SELECT SUM(montant) as montant FROM factures WHERE n_doss='".mysql_real_escape_string($row['n_doss'])."'";
$req7 = mysql_query ($sql7) or die ('Erreur SQL !<br>'.$sql7.'<br>'.mysql_error ());
while($data9 = mysql_fetch_assoc ($req7))
{ $pp=$data9['montant'] ;
if (empty($data9['montant'])) {
echo '0,00'; }
else {
$pp = $data9['montant'] ; $nbr2 = $pp;
// Notation française
$pp = number_format($nbr2, 2, ',', ' ');
// 1 234,56
}
} ?><?php
$sql = "select * from factures where n_doss='".mysql_real_escape_string($row['n_doss'])."' GROUP BY n_doss";
$query = mysql_query($sql);
while ($data=mysql_fetch_assoc($query))
{
$principal = $data['montant'];
$echeance = $data['date_echue'];
$day= date('y-m-d');
$s = strtotime($day)-strtotime($echeance);
$d = intval($s/86400)+1;
$i = (0.0006);
$tx= $principal*($i/360)*$d;
$i2= number_format($tx, 2, ',', ' ');
}
?><?php $sql5 = "SELECT SUM(montant) as montant FROM versements WHERE n_doss='".mysql_real_escape_string($row['n_doss'])."' AND etat ='3'";
$req5 = mysql_query ($sql5) or die ('Erreur SQL !<br>'.$sql5.'<br>'.mysql_error ());
while($data10 = mysql_fetch_assoc ($req5))
{ $nbr4=$data10['montant'] ;
// Notation française
$rgt2 = $nbr4;
$rgt = number_format($nbr4, 2, ',', ' ');
// 1 234,56
}
$versement = $rgt ;
?><?php
$sql253 = "SELECT * FROM `liasses` WHERE n_doss='".mysql_real_escape_string($row['n_doss'])."'";
$req117 = mysql_query ($sql253) or die ('Erreur SQL !<br>'.$sql253.'<br>'.mysql_error ());
$num_rows = mysql_num_rows($req117) ;
if ($num_rows =='0')
{
$sql17 = "SELECT SUM(`factures`.`montant`) AS montant FROM `factures` WHERE `factures`.`n_doss`='".mysql_real_escape_string($row['n_doss'])."'";
}
else
{
$sql17 = "SELECT SUM(`factures`.`montant`) + SUM(`liasses`.`montant`) AS montant FROM `factures` INNER JOIN `liasses` ON `factures`.`n_doss`=`liasses`.`n_doss` WHERE `factures`.`n_doss`='".mysql_real_escape_string($row['n_doss'])."'";
}
$req17 = mysql_query ($sql17) or die ('Erreur SQL !<br>'.$sql17.'<br>'.mysql_error ());
while($data119 = mysql_fetch_assoc ($req17))
{
$sd1 = number_format(($data119['montant']+ $tx-$nbr4) , 2, ',', ' ');
$principal2= $data119['montant'] ;
}
$principal3=$principal2;
echo $sd1;
?>
€</td>
</tr><?php endwhile; ?> <?php }?>
</tbody>
<tfoot>
<!--rangées du tableau-->
</tfoot>
</table>
<p align="right"><?php echo $lignes ; ?> Actions à traiter.
</body>[/php]
ceci est le contenu de ma page et en fait ça me génère un agenda en fonction de certains critères sous la forme d'un tableau.
de l'autre côté j'ai ça qui me permet de générer le pdf grâce à la librairie:
[php]<?php
$content = "
<page>
<h1>Exemple d'utilisation</h1>
<br>
Ceci est un <b>exemple d'utilisation</b>
de <a href='http://html2pdf.fr/'>HTML2PDF</a>.<br>
</page>";
require_once(dirname(__FILE__).'/html2pdf.class.php');
$html2pdf = new HTML2PDF('L','A4','fr');
$html2pdf->WriteHTML($content);
$html2pdf->Output('exemple.pdf');
?>[/php]
Le soucis c'est que je ne sais pas comment récupérer tout mon contenu générer avant en php dans une seule variable $content, j'ai bien essayé en tout concaténant, etc, mais j'ai pleins d'erreurs et ça ne fonctionne pas.
Par avance merci pour votre aide.