I am creating a pdf of 9 columns using mpdf that shows a list of users In each row, 1 column is used for photograph. My problem is that I want the columns to be almost equal in width but in result, I am getting columns with different widths.
I have tried to set CSS of table as well as through mpdf option, but none of them worked. My code is as under:
$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;
Even after setting max width to 70pt, The Old details column takes around 25% of the page width due to which other columns are squeezed badly and look goes weird and also the footer is no more visible.
try the following :
<table cellpadding="5px" autosize="1" border="1" width="100%" style="overflow: wrap">
Then add appropriate widths to your th and td long with appropriate font size, say 8 to 10 pt. Then, at the end, modify your code as follows:
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;
This will lso improve the performance. Dont forget to upvote if this helps.