mpdf 列宽未固定并随数据增加

mpdf columns width is not getting fixed and increases with data

我正在使用显示用户列表的 mpdf 创建 9 列的 pdf 在每一行中,1 列用于照片。我的问题是我希望列的宽度几乎相等,但结果是,我得到的列宽度不同。

我尝试设置 CSS 或 table 以及通过 mpdf 选项,但其中 none 有效。 我的代码如下:

$a='<style>@page {
 margin: 10pt;
}</style>';
$a .= '<table autosize="1" border="1" class="atable" style="font-family:Arial"><tr>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Sr.<br>No.</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Admission No.<br>Boarder/DayScholar<br>Admit Class<br>Admit Date<br>Exit Class<br>Exit Date</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Photograph</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Student Details<br>[Student Name<br>Father Name<br>Father Occupation<br>Mother Name<br>Mother Occupation]</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Date of Birth<br>Current Class<br>Current City<br>Board Roll No.<br>Percentage</th>
<th style="min-width: 60pt;max-width: 70pt; font-size:7pt">Old Details<br>[Address<br>Father Email<br>Father Mobile]</th>
<th style="min-width: 60pt;max-width: 75pt; font-size:7pt">Present Profile<br>(Alumi,<br>Ex-Student,<br>Current Student)</th>
<th style="min-width: 60pt;max-width: 65pt; font-size:7pt">Contact Details<br>[Email Id<br>Mobile<br>Father Mobile<br>Facebook Id<br>Twitter Id<br>Linked In Id]</th>
<th style="min-width: 60pt;max-width: 65pt; font-size:7pt">Remarks</th>
</tr><tr>'

//Here goes the data fetching php code followed by the below code

<td style="font-size: 10pt !important; text-align:center;">' . ++$i . '</td>
<td style="font-size:10pt !important; text-align:center;">' . $row['adm_no'] .'<br><font color="green">' . $row['d_b'] . '</font><br>' . $row['adm_class'] . '<br><font color="green">' . $fadmdate . '</font><br>' . $row['exit_class'] . '<br><font color="green">' . $fexit . '</font></td>
<td style="font-size:10pt !important; text-align:center;">'. '<div id="testimage"><img src="' . $gdImage . '" width="60pt" /></div></td><td style="font-size:10pt !important; text-align:center;">'. $row['stu_name'] .
   '<br><font color="green">' . $row['fat_name'] .  '</font><br>' . $row['fat_occ'] . '<br><font color="green">' . $row['mot_name'] . '</font><br>' . $row['mot_occ'] . '</td>
<td style="font-size:10pt !important; text-align:center;">'.
   $fdob . '<br><font color="green">' . $row['stu_class'] . '</font><br>' . $row['cur_city'] . '<br><font color="green">' .$row['board_roll'] . '</font><br>' . $row['perc'] . '</td>
<td style="font-size:10pt !important; text-align:center;">'.
   $row['addr']. '<br><font color="green">' . $row['fat_email'] . '</font><br>' . $row['fat_mob'] . '</td>
<td style="font-size:10pt !important; text-align:center;">'.
   $cprofile .'</td>
<td style="font-size:10pt !important; text-align:center;">' . $row['email_id'] .'<br><font color="green">' . $row['phone_no'] . '</font><br>' . $row['fb_id'] . '<br><font class="green">' . $row['twitter_id'] . '</font><br>' . $row['linkedin_id'] . '</td><td style="font-size:10pt !important; text-align:left;">SMS:<br><font color="green">Email:</font><br>FB:</td>
</tr></table>
<?php
include("\mpdf\mpdf.php");
$mpdf=new mPDF('','A4');
$keep_table_proportions = TRUE;
$mpdf->shrink_tables_to_fit=1;
$mpdf->setFooter('Details    ::: ' . date("d/m/Y") . ' :::            {PAGENO} / {nb}');
$mpdf->WriteHTML($a);
$mpdf->Output('mytable.pdf', 'D');
exit;

即使将最大宽度设置为 70pt 后,旧的详细信息列仍占据页面宽度的 25% 左右,导致其他列被严重挤压,看起来很奇怪,页脚也不再可见。

尝试以下操作:

<table cellpadding="5px" autosize="1" border="1" width="100%" style="overflow: wrap">

然后用适当的字体大小为你的 th 和 td long 添加适当的宽度,比如 8 到 10 磅。 然后,最后,按如下方式修改您的代码:

include("\mpdf\mpdf.php");
$mpdf=new mPDF('','A4');
$mpdf->simpleTables = true;
$mpdf->packTableData = true;
$mpdf->keep_table_proportions = TRUE;
$mpdf->shrink_tables_to_fit=1;
$mpdf->setFooter('Birthday Details    ::: ' . date("d/m/Y") . ' :::            {PAGENO} / {nb}');
$mpdf->WriteHTML($a);
$mpdf->Output('mytable.pdf', 'D');
exit;

这也会提高性能。有帮助的话别忘了点个赞哦