Probléme avec html2pdf et php

Petit nouveau ! | 7 Messages

15 août 2013, 18:26

Bonjour à tous,
je viens chercher un peu d'aide car j'avoue que je bute .....
Voila j'utilise html2pdf pour réaliser des pdf pour de la gestion de commandes ( la c'est le cas ou c'est du regroupement pour le conditionnement par département )
j'ai déjà un début de code mais j'arrive pas à réaliser l'affichage des contenus par page
genre 1ere page département 66 ( avec la liste des commandes 66 ) page 2 département 11 ( avec la liste des commandes pour le département 11 ) etc ....

voici mon code : ( pas très propre en effet mais je teste )
<?php
    ob_start();

    include ('config/config.php');

    $semaine_plan_va = $_GET['semaine'];
    $annee_plan_va = $_GET['annee'];
    $semaine = $semaine_plan_va;
    $année = $annee_plan_va;
?>

<page backtop="15mm" backbottom="10mm" backleft="20mm" backright="20mm">

    <page_header>
        <table style="width: 100%; border: solid 1px black;">
            <tr>
                <td style="text-align: center;    width: 43%"><b>PLANNING DEPART</b></td>
                <td style="text-align: left;    width: 43%"><b>SEMAINE: <?php echo $semaine ;?> Année : <?php echo $année;?></b></td>
                <td style="text-align: right;    width: 14%"><?php echo date('d/m/Y'); ?></td>
            </tr>
        </table>


    </page_header>

<br>


    <page_footer>
        <table style="width: 100%; border: solid 1px black;">
            <tr>
                <td style="text-align: left;    width: 50%">SCD ALU PLANNING Semaine : <?php echo $semaine?>  &nbsp;&nbsp;Année : <?php echo $année?></td>
                <td style="text-align: right;    width: 50%">page [[page_cu]]/[[page_nb]]</td>
            </tr>
        </table>
    </page_footer>

<tbody>

    <?php




    $sql = "SELECT * FROM planning_scd WHERE plan_s_fab = '".$semaine_plan_va."' AND plan_annee = '".$annee_plan_va."' ORDER BY plan_dep ASC";
    $req = mysql_query($sql) or die ($sql.' '.mysql_error());

    $temp = '';

    while ($data = mysql_fetch_array($req)) {
       if ($temp != $data['plan_dep']) {


 echo'<div align="center"> <table style="width: 95%; border: solid 1px black;">
            <tr>
                <td style="text-align: center;    width: 43%"><b>CHARGEMENT DEPARTEMENT '.$data['plan_dep'].'</b></td>
            </tr>
        </table> </div>';

          $temp = $data['plan_dep'];

       }

        $info_complementaire = htmlentities(trim($data['inf_comp']));
        $detail_chassis_composé = htmlentities(trim($data['comp_com']));


               ?>

         <br>
        <TABLE width=80% style="border: solid 1px black;">
        <TR>
        <TD>



        <TABLE width=100%>
        <TR>
        <TD colspan=3 bgcolor="#C0C0C0" ><b>
        <?php echo'
        Client : &nbsp;&nbsp;', htmlentities(trim($data['plan_client'])) ,' &nbsp;&nbsp; | &nbsp;&nbsp;
        Référence : &nbsp;&nbsp;', htmlentities(trim($data['plan_ref'])) ,' &nbsp;&nbsp; | &nbsp;&nbsp;
        Couleur : &nbsp;&nbsp;',htmlentities(trim($data['plan_couleur'])),' &nbsp;&nbsp; | &nbsp;&nbsp;
        Département : &nbsp;&nbsp;',htmlentities(trim($data['plan_dep'])),' &nbsp;&nbsp;&nbsp;&nbsp;
        ';?>
        </b></TD>
        </TR>
        <TR>
        <TD width="13%" bgcolor="#C0C0C0" ><b>Détails de commande :</b></TD>
        <TD width="87%" >&nbsp;</TD>
        </TR>
        </TABLE>
        <TABLE width=90% >

         <?php
                      if (htmlentities(trim($data['gbi_2vtx'])) > '0' or htmlentities(trim($data['gbi_3vtx'])) > '0' or htmlentities(trim($data['gbi_4vtx'])) > '0' or htmlentities(trim($data['gbi_gal_1vtl'])) > '0' or htmlentities(trim($data['gbi_gal_2vtx'])) > '0' )
                  {
                  echo'<tr><td>';
                  if (htmlentities(trim($data['gbi_2vtx'])) > '0'){ echo'GBI 2 VTX Qté: ', htmlentities(trim($data['gbi_2vtx'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gbi_3vtx'])) > '0'){ echo'GBI 3 VTX Qté: ', htmlentities(trim($data['gbi_3vtx'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gbi_4vtx'])) > '0'){ echo'GBI 4 VTX Qté: ', htmlentities(trim($data['gbi_4vtx'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gbi_gal_1vtl'])) > '0'){ echo'GBI Galandage 1 VTL Qté: ', htmlentities(trim($data['gbi_gal_1vtl'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gbi_gal_2vtx'])) > '0'){ echo'GBI Galandage 2 VTX Qté: ', htmlentities(trim($data['gbi_gal_2vtx'])),' &nbsp;&nbsp;&nbsp;&nbsp;';}
                  echo'</td></tr>';
                  }

              if (htmlentities(trim($data['gy_2vtx'])) > '0' or htmlentities(trim($data['gy_3vtx'])) > '0' or htmlentities(trim($data['gy_4vtx'])) > '0' or htmlentities(trim($data['gy_gal_1vtl'])) > '0' or htmlentities(trim($data['gy_gal_2vtx'])) > '0' )
                  {
                  echo'<tr><td>';
                  if (htmlentities(trim($data['gy_2vtx'])) > '0'){ echo'GY 2 VTX Qté: ', htmlentities(trim($data['gy_2vtx'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gy_3vtx'])) > '0'){ echo'GY 3 VTX Qté: ', htmlentities(trim($data['gy_3vtx'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gy_4vtx'])) > '0'){ echo'GY 4 VTX Qté: ', htmlentities(trim($data['gy_4vtx'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gy_gal_1vtl'])) > '0'){ echo'GY Galandage 1 VTL Qté: ', htmlentities(trim($data['gy_gal_1vtl'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gy_gal_2vtx'])) > '0'){ echo'GY Galandage 2 VTX Qté: ', htmlentities(trim($data['gy_gal_2vtx'])),' &nbsp;&nbsp;&nbsp;&nbsp;';}
                  echo'</td></tr>';
                  }

              if (htmlentities(trim($data['gam_2vtx'])) > '0' or htmlentities(trim($data['gam_3vtx'])) > '0' or htmlentities(trim($data['gam_4vtx'])) > '0' or htmlentities(trim($data['gam_gal_1vtl'])) > '0' or htmlentities(trim($data['gam_gal_2vtx'])) > '0' )
                  {
                  echo'<tr><td>';
                  if (htmlentities(trim($data['gam_2vtx'])) > '0'){ echo'GAM 2 VTX Qté: ', htmlentities(trim($data['gam_2vtx'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gam_3vtx'])) > '0'){ echo'GAM 3 VTX Qté: ', htmlentities(trim($data['gam_3vtx'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gam_4vtx'])) > '0'){ echo'GAM 4 VTX Qté: ', htmlentities(trim($data['gam_4vtx'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gam_gal_1vtl'])) > '0'){ echo'GAM Galandage 1 VTL Qté: ', htmlentities(trim($data['gam_gal_1vtl'])),' &nbsp;&nbsp;|&nbsp;&nbsp;';}
                  if (htmlentities(trim($data['gam_gal_2vtx'])) > '0'){ echo'GAM Galandage 2 VTX Qté: ', htmlentities(trim($data['gam_gal_2vtx'])),' &nbsp;&nbsp;&nbsp;&nbsp;';}
                  echo'</td></tr>';
                  }

              if (htmlentities(trim($data['fy_fixe'])) > '0' or htmlentities(trim($data['fy_1vtl'])) > '0' or htmlentities(trim($data['fy_2vtx'])) > '0' or htmlentities(trim($data['fy_1vtl_ob'])) > '0' or htmlentities(trim($data['fy_2vtx_ob'])) > '0' )
                  {
                  echo'<tr><td>';
                  if (htmlentities(trim($data['fy_fixe'])) > '0'){ echo'FY Fixe Qté: ', htmlentities(trim($data['fy_fixe'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['fy_1vtl'])) > '0'){ echo'FY 1 VTL Qté: ', htmlentities(trim($data['fy_1vtl'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['fy_2vtx'])) > '0'){ echo'FY 2 VTX Qté: ', htmlentities(trim($data['fy_2vtx'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['fy_1vtl_ob'])) > '0'){ echo'FY 1 VTL OB Qté: ', htmlentities(trim($data['fy_1vtl_ob'])),' &nbsp;&nbsp;|&nbsp;&nbsp;';}
                  if (htmlentities(trim($data['fy_2vtx_ob'])) > '0'){ echo'FY 2 VTX OB Qté: ', htmlentities(trim($data['fy_2vtx_ob'])),' &nbsp;&nbsp;&nbsp;&nbsp;';}
                  echo'</td></tr>';
                  }


              if (htmlentities(trim($data['fd_fixe'])) > '0' or htmlentities(trim($data['fd_1vtl'])) > '0' or htmlentities(trim($data['fd_2vtx'])) > '0' or htmlentities(trim($data['fd_1vtl_ob'])) > '0' or htmlentities(trim($data['fd_2vtx_ob'])) > '0' )
                  {
                  echo'<tr><td>';
                  if (htmlentities(trim($data['fd_fixe'])) > '0'){ echo'FD Fixe Qté: ', htmlentities(trim($data['fd_fixe'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['fd_1vtl'])) > '0'){ echo'FD 1 VTL Qté: ', htmlentities(trim($data['fd_1vtl'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['fd_2vtx'])) > '0'){ echo'FD 2 VTX Qté: ', htmlentities(trim($data['fd_2vtx'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['fd_1vtl_ob'])) > '0'){ echo'FD 1 VTL OB Qté: ', htmlentities(trim($data['fd_1vtl_ob'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['fd_2vtx_ob'])) > '0'){ echo'FD 2 VTX OB Qté: ', htmlentities(trim($data['fd_2vtx_ob'])),' &nbsp;&nbsp;&nbsp;&nbsp;';}
                  echo'</td></tr>';
                  }

              if (htmlentities(trim($data['py_1vtl'])) > '0' or htmlentities(trim($data['py_2vtx'])) > '0' )
                  {
                  echo'<tr><td>';
                  if (htmlentities(trim($data['py_1vtl'])) > '0'){ echo'PY 1 VTL Qté: ', htmlentities(trim($data['py_1vtl'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['py_2vtx'])) > '0'){ echo'PY 2 VTX Qté: ', htmlentities(trim($data['py_2vtx'])),' &nbsp;&nbsp;&nbsp;&nbsp;';}
                  echo'</td></tr>';
                  }


              if (htmlentities(trim($data['comp_coul'])) > '0' or htmlentities(trim($data['com_frap'])) > '0' )
                  {
                  echo'<tr><td>';
                  echo'<b>Chassis Composés : </b>';
                  echo'</td></tr>';
                  echo'<tr><td>';
                  if (htmlentities(trim($data['comp_coul'])) > '0'){ echo'Composé Coulissant Qté: ', htmlentities(trim($data['comp_coul'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['comp_frap'])) > '0'){ echo'Composé Frappe Qté: ', htmlentities(trim($data['comp_frap'])),' &nbsp;&nbsp;&nbsp;&nbsp;';}
                  echo'</td></tr>';

                  echo'<tr><td>';
                  echo'<b>Description Des Composés : </b>';
                  echo'</td></tr>';
                  echo'<tr><td>';
                  echo html_entity_decode($detail_chassis_composé);
                  echo'</td></tr>';
                  }


              if (htmlentities(trim($data['vr'])) > '0' or htmlentities(trim($data['vr_frap'])) > '0')
                  {
                  echo'<tr><td>';
                  echo'<b>Vr ( compris dans le lot Coulissant et Frappe ) :</b>';
                  echo'</td></tr>';
                  echo'<tr><td>';
                  if (htmlentities(trim($data['vr'])) > '0'){ echo'Volets Sur coulissant Qté: ', htmlentities(trim($data['vr'])),' &nbsp;&nbsp; | &nbsp;&nbsp;';}
                  if (htmlentities(trim($data['vr_frap'])) > '0'){ echo'Volets Sur Frappe Qté: ', htmlentities(trim($data['vr_frap'])),' &nbsp;&nbsp;&nbsp;&nbsp;';}
                  echo'</td></tr>';
                  echo'<tr><td>';
                  echo'<b>Détails des châssis avec Vr :</b>';
                  echo'</td></tr>';
                  echo'<tr><td>';
                  echo html_entity_decode($info_complementaire);
                  echo'</td></tr>';
                  }


        ?>
        </TABLE>


     </TD>
     </TR>
        </TABLE>




        <?php


echo'<br><br>';






    }
    mysql_free_result($req);

    mysql_close($connexion);

    ?>

</tbody>

</page>



<?php

    $content = ob_get_clean();

    // convert to PDF
    require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php');
    try
    {
        $html2pdf = new HTML2PDF('L', 'A4', 'fr',false,'ISO-8859-15');
        $html2pdf->pdf->SetDisplayMode('fullpage');
        $html2pdf->setDefaultFont('Arial');
        $html2pdf->writeHTML($content);
        $html2pdf->Output('test.pdf');
    }
    catch(HTML2PDF_exception $e) {
        echo $e;
        exit;
    }

    ?>
et le résultat en pdf :
http://www.letoutweb.com/pdf/test.pdf

Si une âme charitable veut bien m'aider :)

Merci par avance :D

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

16 août 2013, 10:44

Salut,

Rajoute une page à chaque nouveau département http://wiki.spipu.net/doku.php?id=html2pdf:fr:v4:page.
Tu peux préciser un pagset="old" pour ne pas reprendre les entêtes et pieds de pages.



@+
Il en faut peu pour être heureux ......

Petit nouveau ! | 7 Messages

16 août 2013, 14:42

Salut,

oui j'ai vu cela .... mais déjà il faut que j'arrive à dissocier les départements qui en résultent suivant la requête

j'ai penser afficher justement un pagset="old" une fois que l'un des département est affiché dans le <tbody>.... et c'est la que je bloque #-o

En fait pour decomposer il faut que j'affiche tous les résultats du département 11 dans le <tbody> <\tbody>et si j'ai d'autres résultats de département ben les afficher dans le pagset="old"

Et j'y arrive pas ahhhh du moins à structurer tout cela.

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

16 août 2013, 18:49

Il faut que tu organise une césure dans ta boucle while.

En général cela ce résume à vérifier que l'état courant soit différente de l'état précédent.

c'est pas clair ?

en gros
<?php
$ret = mysql_query($sql);
$oldDep= null;
while($data = mysql_fetch_assoc($ret)){
    // on initialise $oldDep
    if(empty($oldDep)) {
        $oldDep = $data['departement'];
    }
    // si le departement du jeux de résultat courant est différent du précédent
    // on ferme proprement la page et on ajoute une nouvelle
    if($data['departement'] != $oldDep) {
        $oldDep = $data['departement'];
        echo '</tbody></page><page pageset="oldset"><tbody>';
    }
    // le traitement existant
}
Bon c'est à adapter a ton code mai le principe est la ;)

ce principe est utiliser facilement pour, par exemple, changer les couleurs des lignes dans un tableau html.

@+
Il en faut peu pour être heureux ......