Je rencontre des problèmes lors de la génération du code HTML/PHP au format PDF. Im en utilisant MPDF Voici mon code:Erreur MPDF lors de la génération au format PDF
<table id="packing_slip">
<?php
foreach($sheets as $s):
echo "<tr>";
echo "<td>";
$name= explode(' ',$s['customer_name'])
?>
<div style="text-align: center">
</div>
<h2 style="text-align: center">Hi <?php echo $name[0] ?>!</h2>
<div align="center">
<br> Here is your delivery for: <br>
<?php echo date('l, F dS', strtotime($s['delivery_week']));?>
<br>
ORDER NO. <?php echo $s['order_id'] ?> | CUSTOMER NO.<?php echo $s['client_id'] ?>
<?php $query="select * from orders left join deliveries on orders.id = deliveries.order_id left join deliveries_meals on deliveries.id = deliveries_meals.delivery_id where orders.id = '{$s['order_id']}'";
$result_main = mysqli_query($conn,$query);
$row_main = mysqli_fetch_assoc($result_main);
$query_meals = "select label, subtitle, meals.name from meal_options left join meals on meal_options.meal_id = meals.id where meal_options.id ='{$row_main['meal_option_id']}' ";
$result_meals = mysqli_query($conn,$query_meals);
$row_meals = mysqli_fetch_assoc($result_meals);
?>
<hr style="height: 5px;border-top:1px solid #000 !important;margin-bottom:0px">
<hr style="height: 5px;border-top:1px solid #000 !important;margin-top: 5px !important;">
</div>
<?php foreach($s['meals'] as $m):?>
<h3><?php echo $row_meals['name'];?> </h3>
<h5><i><?php
if($row_meals['label'] != '' && $row_meals['subtitle'] != ''){ echo $row_meals['subtitle'] . " & " . $row_meals['label'];}
elseif ($row_meals['label'] != '') {echo "with " . $row_meals['label'];}
else{ echo $row_meals['subtitle'];}?></i> </h5>
<?php echo $m['count']?> SERVING SHIPPED<br><br>
COMPONENTS
<hr align = "left" style="width: 115px; border-top:1px solid #000 !important;margin-top: 5px !important;margin-bottom:0px">
<br>
<?php if (@$m['components'][0] != ''){?>
<?php foreach($m['components'] as $c):?>
<?php echo $c?><br>
<?php endforeach;
} else {echo "Everything is included in package. <br>";}
?>
<br>
<?php if($m['instructions'][0] != '' || $m['instructions'][1] !=''){?>
INSTRUCTIONS
<hr align = "left" style="width: 115px; border-top:1px solid #000 !important;margin-top: 5px !important;margin-bottom:0px">
<br>
<?php if($m['instructions'][0] != ''){echo "Microwave : ".$m['instructions'][0];}?><br><br>
<?php if($m['instructions'][1] != ''){ echo "Stovetop : ".$m['instructions'][1];}?><br>
<?php }?>
<hr align="left" style="width: 400px; border-top:1px solid #000 !important;margin-top: 5px !important;margin-bottom:0px" >
<?php endforeach;?>
<hr align="left" style="width: 600px; border-top:1px solid #000 !important;margin-top: 5px !important;margin-bottom:0px" >
<div align="center"><h3> Thank you,<?php echo $name[0] ?>!</h3>
<hr style="width: 600px; border-top:1px solid #000 !important;margin-top: 5px !important;margin-bottom:0px" >
</div>
<br>
<br>
<br>
<br>
<br>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php
include('mpdf60/mpdf.php');
$mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);
$mpdf->debug = true;
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
$mpdf->WriteHTML('<p style="color:red;">Hello World<br/>Fisrt sentencee</p>');
$mpdf->Output();
exit;
?>
Je mis pour l'instant « Bonjour tout le monde » mais je veux vraiment mettre mon code tout, aussi je reçois cette erreur: Output has already been sent from the script - PDF file generation aborted.
Comment puis-je résoudre ce problème? J'utilise FuelPhp, je ne sais pas comment je peux l'ajouter au PDF, des idées sur la façon dont cela peut fonctionner. Parce que maintenant il ne me laisse même pas mettre "Hello World"
J'ai essayé la première option avec le 'ob_start(); cependant un pdf télécharge mais quand je l'ouvre je reçois" Impossible de charger le document PDF. " avez-vous une idée de pourquoi cela se passe? – john
Aussi fait 'ob_start(); 'doit être au tout début de la page? – john
Si vous envoyez le PDF à télécharger ou à afficher dans le navigateur, vous ne devez rien imprimer vous-même, même après * l'appel de la méthode 'Output'. Donc oui, ob_start devrait être au début de votre code, et il ne doit pas y avoir de sortie (print/echo/etc) après avoir appelé la méthode 'Output'. – Finwe