Je rencontre une petite singularité qui m'intrigue.
Je créé un pdf en appelant le fichier contenant HTML séparément comme présenter dans les exemples, par le biais de ce script :
<?php
ob_start();
include('template_devis.php');
$content = ob_get_clean();
require_once("html2pdf/html2pdf.class.php");
try
{
$html2pdf = new HTML2PDF('P', 'A4', 'fr');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->WriteHTML($content);
ob_clean();
$html2pdf->Output('test_43.pdf');
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
?>De cette manière le fichier pdf créer commence automatique par une page blanche contenant un seul caractère "?".
Si maintenant je ne fais appel au fichier template_devis.php, mais que j'intègre son contenu dans mon code directement, je n'ai plus le problème.
<?php
ob_start();
?>
<style type="text/css">
<!--
table {
width:100%;
vertical-align: middle;
}
td {
vertical-align: middle;
}
-->
</style>
<page style="text-align: left; width: 100%; font-family: Arial, Helvetica, sans-serif; font-size:11px; line-height: 9pt; color: #000;">
<bookmark title="Devis" level="0" ></bookmark>
<table cellspacing="0" cellspacing="0" style="width: 100%; text-align: left;">
<tr>
<td style="width: 60%">
<img src="http://www.bachecreation.net/images/index3/header_pdf.jpg" /><br>
<span style="font-size: 8px; color: #706F6F; font-weight:bold;"><i>Leader français de la vente en ligne de bâche sur mesure</i></span><br>
<p style="font-size: 9px; color: #706F6F;">
180 rue de la pièce Grande - P.A. Cahors Sud<br>
Zone Entest - 46230 FONTANES<br>
Tél: 05 65 20 85 26 - Fax: 05 65 31 82 54<br>
Mail: contact@bachecreation.com<br>
www.bachecreation.com
</p>
</td>
<td style="width: 40%">
<p style="margin-top:20px; margin-left:5px;">
Fontanes, le <?php echo date('d-m-Y');?><br><br>
<?php echo htmlspecialchars_decode($secondname).' '.htmlspecialchars_decode($firstname); ?><br>
<?php echo "$emailto"; ?>
<?php echo "$tele"; ?>
<?php echo htmlspecialchars_decode($address)."<br>".$codepostal." ".htmlspecialchars_decode($ville); ?>
</p>
</td>
</tr>
</table>
<br><br>
<table cellspacing="0" cellspacing="0" style="width: 100%; border: 1px solid #676767; width: 100%; text-align: left;">
<tr>
<td colspan="2" style="background-color: #DADADA; vertical-align: top; border-bottom : 1px solid #676767; padding:10px;" >
<span style="font-size:17px; text-transform:uppercase; font-weight:bold;">Devis n° <?php echo " $devisnum";?></span>
</td>
</tr>
<tr>
<td style="color: #706F6F; background-color: #F6F6F6; font-size:12px; font-weight:bold; border-bottom : 1px solid #676767; width: 60%; padding : 5px 0px 5px 10px;">
<?php echo htmlspecialchars_decode($productname);?>
</td>
<td style="text-align:right; color: #706F6F; background-color: #F6F6F6; font-weight:bold; border-bottom : 1px solid #676767; width: 40%; padding : 5px 10px 5px 0px;">
Quantité : 1
</td>
</tr>
<tr>
<td style="width: 60%; line-height : 12pt; padding: 10px;">
<?php foreach ($pdfdesc_array as $key => $value){echo "$value<br/>";} ?>
</td>
<td style="width: 40%; vertical-align: top !important;">
<?php //echo "<img align=\"left\" src=\"".$productpic."\" />"; ?>
</td>
</tr>
</table>
<br><br>
<table cellspacing="0" cellspacing="0" style="width: 100%; text-align: left;">
<tr>
<td style="width:70%; color: #999; font-size: 9px;">
Délais de fabrication et livraison actuel : <?php echo $config['delay']; ?> semaine<br>
Règlement possible par carte bancaire, chèque et virement<br>
BON POUR ACCORD : Date et signature<br><br>
<div style=" border: 1px solid grey; background-color:#F6F6F6; width:260px; height:50px;"></div>
</td>
<td style="width:15%; text-align:right; padding:5px; border:1px solid grey; line-height:16pt;">
Sous-total H.T. :<br>
Remise<?php echo $remise;?> :<br>
T.V.A. (19,6%) :<br>
<b>Total T.T.C :</b>
</td>
<td style="width:15%; text-align:left; padding:5px; padding-left: 20px; border:1px solid grey; border-left: none; line-height:16pt; ">
<?php echo $ht; ?> €<br>
<?php echo $disp_remise; ?> €<br>
<?php echo $disp_tva;?> €<br>
<b><?php echo $prixttc;?> €</b>
</td>
</tr>
</table>
<page_footer style="width: 100%; text-align:center; color: #999; font-size: 9px; margin-top:20px;">
<p style="width:100%; height:1px; border-top: 1px solid grey;">©2013 Bâche Création - SIRET: 48063415300039 - RCS: Cahors B 480 634 153 - TVA: FR90480634153</p>
</page_footer>
</page>
<?php
$content = ob_get_clean();
// convert to PDF
require_once("html2pdf/html2pdf.class.php");
try
{
$html2pdf = new HTML2PDF('P', 'A4', 'fr');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->WriteHTML($content);
ob_clean();
$html2pdf->Output('test_43.pdf');
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
?>Je joins également le fichier pdf résultant avec l'erreur.
Merci d'avance pour votre lecture.
Fichier joint : test_43.pdf