J'ai essayé de nombreuses façons d'adapter le tableau à la page (A4) comme indiqué sur l'image: j'ai beaucoup cherché mais je n'ai rien trouvé d'utile sur le web. J'utilise une table dynamique, tout va bien sauf la largeur de la table. voici mon code:
$content = '<table><thead><tr><th class="bg-dark text-white" align="center">#</th><th align="center" class="bg-dark text-white">Code</th><th align="left" class="bg-dark text-white">Description</th><th align="center" class="bg-dark text-white">Item Type</th></tr></thead><tbody><tr style="background-color: #f2f2f2;"><td align="center">1</td><td align="center">1001</td><td align="left">Pofak</td><td align="center">Fixed Price</td></tr><tr ><td align="center">2</td><td align="center">1002</td><td align="left">Ice</td><td align="center">Weight</td></tr><tr style="background-color: #f2f2f2;"><td align="center">3</td><td align="center">1003</td><td align="left">Minoo</td><td align="center">Fixed Price</td></tr><tr ><td align="center">4</td><td align="center">1004</td><td align="left">Bastani</td><td align="center">Fixed Price</td></tr><tr style="background-color: #f2f2f2;"><td align="center">5</td><td align="center">1005</td><td align="left">Chocolate</td><td align="center">Weight</td></tr><tr ><td align="center">6</td><td align="center">1006</td><td align="left">Brush</td><td align="center">Fixed Price</td></tr><tr style="background-color: #f2f2f2;"><td align="center">7</td><td align="center">1007</td><td align="left">Apple</td><td align="center">Weight</td></tr><tr ><td align="center">8</td><td align="center">1008</td><td align="left">Water</td><td align="center">Fixed Price</td></tr><tr style="background-color: #f2f2f2;"><td align="center">9</td><td align="center">1009</td><td align="left">Cleaner</td><td align="center">Fixed Price</td></tr><tr ><td align="center">10</td><td align="center">1001</td><td align="left">Pofak</td><td align="center">Fixed Price</td></tr><tr style="background-color: #f2f2f2;"><td align="center">11</td><td align="center">1002</td><td align="left">Ice</td><td align="center">Weight</td></tr><tr ><td align="center">12</td><td align="center">1003</td><td align="left">Minoo</td><td align="center">Fixed Price</td></tr><tr style="background-color: #f2f2f2;"><td align="center">13</td><td align="center">1004</td><td align="left">Bastani</td><td align="center">Fixed Price</td></tr><tr ><td align="center">14</td><td align="center">1005</td><td align="left">Chocolate</td><td align="center">Weight</td></tr><tr style="background-color: #f2f2f2;"><td align="center">15</td><td align="center">1006</td><td align="left">Brush</td><td align="center">Fixed Price</td></tr></tbody></table>';
$newContent = '
<style type="text/css">
table{width:100%;}
table, table td, table th{
border-collapse: collapse;
border: solid 1px #ababab;
}
.text-dark, table td{
color: #343a40;
}
.text-white{
color: #ffffff;
}
table td,
table th {
font-size: 11px;
padding: 3px;
line-height: 1.2;
font-family:arial;
}
.bg-dark {
background-color: #343a40;
}
.bg-secondary {
background-color: #6c757d;
}
.bg-white {
background-color: #ffffff;
}
.text-left {
text-align: left;
}
.text-right {
text-align: right;
}
.text-center {
text-align: center;
}
</style>
';
$newContent .= '<page>'.$content.'</page>';
try {
$html2pdf = new Html2Pdf('P', 'A4', 'en', true, 'UTF-8', 5);
$html2pdf->pdf->SetDisplayMode('real');
$html2pdf->writeHTML($newContent);
$PDFName = "ItemLists_".date('Y.m.d_H.i.s').".pdf";
$html2pdf->output($PDFName, 'I');
} catch (Html2PdfException $x) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($x);
echo $formatter->getHtmlMessage();
}
Merci beaucoup
style="width: 100%"
stocke la largeur correctement convertie en MM (bien que l'attribut width ne le fasse pas!) Cependant Html2PDF ne semble pas l'utiliser réellement pendant le rendu de la table.