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>
le soucis c'est que je ne sais pas comment tout récupérer dans la variable $content,
j'ai essayé avec la fonction de bufferisation ou la fonction readfile, ou même de concaténer mais j'ai plein de messages d'erreur et cela ne marche pas,
d'avance merci pour votre aide.
J'ai essayé ainsi,
<?php ob_start(); ?>
<table border="0" width="100%"><tr><td align="center" colspan="2"><?php
if (isset($_REQUEST['tache']))
{
$date1= date('Y-m-d',strtotime($_REQUEST['date1']));
$date2= date('Y-m-d',strtotime($_REQUEST['date2']));
$sql = "SELECT * FROM agenda WHERE action LIKE '%".mysql_real_escape_string($_REQUEST['tache'])."%' AND date_action > '".$date1."' AND date_action < '".$date2."' AND date_validation='0000-00-00' ORDER BY date_action";
$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" width="168" height="24"></td></tr><tr><td nowrap>Du <?php echo $_REQUEST['date1'] ; ?> Au <?php echo $_REQUEST['date2'] ; ?>, Critères : <?php echo $_REQUEST['tache'] ; ?></td><td nowrap align="right">édité le <?php echo date('d-m-Y') ; ?> Par <?php echo strtoupper($_SESSION['login']) ; ?></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>DEBITEUR</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><tbody>
<?php while($row = mysql_fetch_assoc($qry)): ?>
<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 debiteur 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.</p>
<?php $content=ob_get_contents();
ob_end_clean();
require_once('html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML($content);
$html2pdf->Output('monagenda.pdf');
?>
mais cela me renvoi l'erreur sous-jacente:
( ! ) Notice: Undefined offset: 17 in C:\wamp\www\NEOGETCASH\GESTIONNAIRE\html2pdf.class.php on line 4957
Call Stack
# Time Memory Function Location
1 0.0008 769664 {main}( ) ..\impressionagenda.php:0
2 0.2740 17309816 HTML2PDF->writeHTML( ) ..\impressionagenda.php:169
3 0.3597 18018624 HTML2PDF->_makeHTMLcode( ) ..\html2pdf.class.php:408
4 1.2486 18725512 HTML2PDF->_executeAction( ) ..\html2pdf.class.php:1218
5 1.2486 18725648 HTML2PDF->_tag_close_TABLE( ) ..\html2pdf.class.php:1255
TCPDF ERROR: Some data has already been output, can't send PDF file
voila ce qu'il me dit désormais mais on s'approche du résultat grâce à vous, merci beaucoup.
Spipu Le 08/06/2012 à 18:07 en effet, c'est les méthodes de bufferisation OB_START et OB_GET_CLEAN qu'il faut utiliser.
concernant l'erreur, il se peut que ce soit à cause du tfoot qui soit vide.