Bonjour,
Voila je rencontre un petit problème avec mon code.
Ce que je fais
J'ai développé une application de gestion qui imprime des bordereaux mais pourlancer l'impression, je doit d'abord faire un apercu en pdf et la l'utilisateur peut depuis l'aperçu imprimer son document pour cela j'utilise la méthode archaique que voici:
j'ai un repertoire src/Lib/html1pdf qui contient mes fichiers de génération en pdf
dans mon layout export je n'ai rien comme script par contre dans mon action FactureGlobale de mon Controller ImprimerController.php, j'ai ceci
public function FactureGlobale()
{
$this->autoRender = false;
$users = TableRegistry::get('Administration.Users');
$listecolis = TableRegistry::get('Administration.Colis');
$conn = ConnectionManager::get('default');
$user = $users->find()->where(['Users.id'=>$this->Auth->user('id'),'agence_id'=>$this->Auth->user('agence_id')])->contain(['Agences'])->first();
$autresagence= $conn->execute("SELECT phone,ville, num_rc FROM agences, entreprises WHERE agences.entreprise_id = entreprises.id AND entreprises.etat = 1 AND agences.etat=1")->fetchAll('assoc');
$colis = $listecolis->find()->select(['code_colis','frais','nature','type_payement','nom_expediteur','telephone_expediteur','created','etat'])->where(['Colis.etat >=' =>1,'Colis.etat !='=>4])->contain(['Agences'=>function($agence){
return $agence->select(['nom_agence']);
}])->order(['Colis.created DESC'])->all();
//debug($user);die();
$this->set(compact('colis','user','autresagence'));
$this->render('Administration.Impressions/pdf/total_factures');
}
et dans ma vew total_factures.ctp,j'ai ceci:
<?php
header("Content-type: application/pdf");
//debug(APP . 'Lib'. DS . 'html2pdf'. DS . 'tcpdf' . DS . 'tcpdf.php');die();
require_once APP . 'Lib'. DS . 'html2pdf'. DS . 'tcpdf' . DS . 'tcpdf.php';
require_once APP . 'Lib'. DS . 'html2pdf'. DS . 'tcpdf' . DS . 'tcpdf_autoconfig.php';
require_once APP . 'Lib'. DS . 'html2pdf'. DS . 'tcpdf' . DS . 'tcpdf_barcodes_1d.php';
require_once APP . 'Lib'. DS . 'html2pdf'. DS . 'tcpdf' . DS . 'tcpdf_import.php';
require_once APP . 'Lib'. DS . 'html2pdf'. DS . 'tcpdf' . DS . 'config'. DS .'tcpdf_config.php';
require_once APP . 'Lib'. DS . 'html2pdf' . DS . 'html2pdf.php';
require_once APP . 'Lib'. DS . 'html2pdf' . DS . 'HTML2PDF_locale.php';
require_once APP . 'Lib'. DS . 'html2pdf' . DS . 'HTML2PDF_myPdf.php';
require_once APP . 'Lib'. DS . 'html2pdf' . DS . 'HTML2PDF_exception.php';
require_once APP . 'Lib'. DS . 'html2pdf' . DS . 'HTML2PDF_parsingCss.php';
require_once APP . 'Lib'. DS . 'html2pdf' . DS . 'HTML2PDF_parsingHtml.php';
?>
<?php ob_start();?>
<style type="text/css">
<!--
h1 {color: #000033}
h2 {color: #000055}
h3 {color: #000077}
.entete-bordereau table {
border-collapse:collapse;
}
.entete-bordereau th, .entete-bordereau td {
border-bottom:1px solid black;
}
.entete-bordereau td {
text-align:center;
}
.design {
width: 98%;
border-collapse: collapse;
}
.design th, .design td {
padding: 3px;
border: 1px solid #000;
text-align: center;
}
.design th {
font-weight: bold;
}
table tr {
border-bottom:4px solid green;
}
-->
</style>
<page backtop="10mm" backbottom="10mm" backleft="20mm" backright="20mm" style="font-size: 12px">
<page_header>
<table style="width: 100%;">
<tr>
<td style="text-align: left; width: 25%">
</td>
<td style="text-align: center; width: 50%">
<?php echo '<img src="'. WWW_ROOT . 'img' . DS . 'facture.png' .'" width="0%"/>';?>
</td>
<td style="text-align: right; width: 25%">
</td>
</tr>
</table>
<table style="width: 100%;">
<tr>
<td style="text-align: left; width: 25%;font-size: 10px;">
Agence de <?php echo $user->agence->nom_agence;?><br/>
Ville <?php echo $user->agence->ville;?>
</td>
<td style="text-align: left; width: 2%">
</td>
<td style="text-align: center; width: 48%; font-size: 10px;">
<h5>LISTE TOTALE DE COLIS</h5><br/><i> Période du <?php echo date("Y-d-m H:i:s");?> </i>
</td>
<td style="text-align: right; width: 25%;font-size: 10px;">
<?php foreach ($autresagence as $key => $value):?>
Service courrier <?php echo $value['ville'];?> : <?php echo $value['phone'];?><br/>
<?php endforeach;?>
</td>
</tr>
</table>
<br/><br/><br/>
<table style="width: 100%;font-size: 10px;">
<tr>
<td style="text-align: left; width: 40%">
Nom de l'agent:<?php echo $user->prenom;?> <?php echo $user->nom;?>
</td>
<td style="text-align: center; width: 10%">
</td>
<td style="text-align: right; width: 10%">
</td>
<td style="text-align: right; width: 40%">
</td>
</tr>
</table>
<br/><br/><br/>
<table style="font-size: 10px; width: 100%; " class="entete-bordereau">
<tr>
<td style="text-align: center; width: 5%">#</td>
<td style="text-align: center; width: 15%">Destination</td>
<td style="text-align: center; width: 10%">Code</td>
<td style="text-align: center; width: 20%">Nature</td>
<td style="text-align: center; width: 6%">Payement</td>
<td style="text-align: center; width: 10%">Montant</td>
<td style="text-align: center; width: 13%">Expéditeur / Contact</td>
<td style="text-align: center; width: 10%">Date</td>
<td style="text-align: center; width: 9%">Etat</td>
</tr>
<?php $k = 1; ?>
<?php foreach ($colis as $key => $value):?>
<tr>
<td style="text-align: left; width: 5%"><?php echo $k; ?></td>
<td style="text-align: left; width: 15%"><?php echo $value->agence->nom_agence; ?></td>
<td style="text-align: left; width: 10%"><?= $value->code_colis; ?></td>
<td style="text-align: left; width: 20%"><?php echo wordwrap($value->nature,25,"<br/>\n",true); ?></td>
<td style="text-align: left; width: 6%"><?php echo $value->type_payement; ?></td>
<td style="text-align: left; width: 10%"><?php echo $value->frais; ?>CFA</td>
<td style="text-align: left; width: 15%"><?php echo wordwrap($value->nom_expediteur,25,"<br/>\n",true) . "<br/>Tel:" . $value->telephone_expediteur; ?></td>
<td style="text-align: left; width: 10%"><?= $value->created->format('Y-m-d H:i:s'); ?></td>
<td style="text-align: left; width: 9%"> <?php if($value->etat == 1): ?>
<span class='badge badge-hero badge-warning'>Nouveau...</span>
<?php endif; ?>
<?php if($value->etat == 2): ?>
<span class='badge badge-hero badge-danger'>En route...</span>
<?php endif; ?>
<?php if($value->etat == 3): ?>
<span class='badge badge-hero badge-primary'>Receptionner...</span>
<?php endif; ?>
<?php if($value->etat == 4): ?>
<span class='badge badge-hero badge-success'>Retirer...</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</page_header>
<page_footer>
</page_footer>
</page>
<?php $content = ob_get_clean();
try{
$pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', array(0, 0, 0, 0));
// $pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', 0);
$pdf->pdf->SetDisplayMode('fullpage');
$pdf->pdf->SetAuthor('PRINCESSE VOYAGES');
$pdf->pdf->SetTitle('Facture colis');
$pdf->pdf->SetSubject('Exportation de facture');
$pdf->pdf->SetKeywords('facture colis, importation, colis');
$pdf->writeHTML($content);
$pdf->Output('facture.pdf');
echo $pdf->Output(ROOT . 'facture_colis' . DS . 'facture.pdf', 'FI');
}
catch(HTML2PDF_exception $e){
die($e);
}
?>
déjà l'impression se passe bien sauf pour moins de 30 lignes
si j'ai un enregistrement de plus de 30 lignes déà cela va prendre un temps fou pour charger et après j'aurais une belle erreur du genre time out ,
Ce que je veux
Décrivez ici ce que vous cherchez à obtenir
Ce que j'obtiens
j'obtiens des messages qui me signale que ma requete est trop longue, le serveur prend trop de temps pour charger .
En passant en local j'ai aussi le même problème
quelqu'un a déjà eu ce problème?
si non une autre solution optimisée pour faire le print d'un document en pdf
SVP