【问题标题】:mpdf columns width is not getting fixed and increases with datampdf 列宽没有得到固定并随着数据的增加而增加
【发布时间】:2017-05-27 12:21:49
【问题描述】:

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

我尝试过设置表格的 CSS 以及通过 mpdf 选项,但它们都不起作用。 我的代码如下:

$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% 左右,因此其他列被严重挤压,看起来很奇怪,页脚也不再可见。

【问题讨论】:

    标签: php html pdf pdf-generation mpdf


    【解决方案1】:

    尝试以下方法:

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

    然后使用适当的字体大小为您的 th 和 td long 添加适当的宽度,例如 8 到 10 pt。 然后,最后,修改您的代码如下:

    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;
    

    这也将提高性能。如果这有帮助,请不要忘记投票。

    【讨论】:

    • 是的,看起来这种方法很有效。谢谢。
    • 那一行应该是:$mpdf->keep_table_proportions = true;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2018-01-29
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    相关资源
    最近更新 更多