How to prevent table resizing in PDF using mPDF and PHP?

穿精又带淫゛_ 提交于 2019-12-14 02:17:10

问题


I have some form data and after submitting, a PDF is generated. The problem is size of tables in PDF. If some string in my form is too long the PDF is generated wrongly. It's because the tables. They have static size so if string is too long the table did not accommodate it. I use mPDF library.

How can I make this tables size dynamics so as to their size changed depending on the length of string?

If string {p} is longest then width of table the table size decrease. I want to if the string {p} is longest than width of table then {p} should writing out in next line and the height of table should increase.

A screenshot if string in field (name) is short:

A screenshot if string in field (name) is long:

A screenshot if string in field (name) is very long:

Here is a fragment of code with mPDF:

$mpdf=new mPDF('UTF-8','A4','','',20,15,48,25,10,10);

$mpdf->shrink_tables_to_fit=1;
$mpdf->keep_table_proportions = true;
$mpdf->WriteHTML(generatePDF());
$mpdf->AddPage();
$mpdf->WriteHTML(generatePDF2());

$mpdf->Output();
exit;

And fragment of HTML tables:

function generatePDF(){
    global $a,$b,$c,$d;
    $html = getHTMLStyle().'

<div style="text-align: left;"><span style="font-size: 11pt;font-weight: bold;">FORMULARZ KONSULTACJI<br />PROJEKTU PRAWA MIEJSCOWEGO<br /> W ZAKRESIE DZIAŁALNOŚCI STATUTOWEJ ORGANIZACJI POZARZĄDOWEJ*<br /><br /></span></div>

<table class="items" width="100%" style="font-size: 9pt; border-collapse: collapse;" cellpadding="8">

<tr>
<td width="5%">A</td>
<td width="95%"><b>'.$a.'</b><br /><br /> '.$_POST['title'].'</td>
</tr>

回答1:


Here:

<tr>
<td width="5%">A</td>
<td width="95%"><b>'.$a.'</b><br /><br /> '.$_POST['title'].'</td>
</tr>

Try using a fixed value for table width instead of a percent. something like:

<table class="items" width="950" style="font-size: 9pt; border-collapse: collapse;" cellpadding="8">

And see what happens.




回答2:


It is really hard to find the problem, but the answer is simple. table with style="overflow:wrap" after reading the source code:

elseif ($table['overflow']=='wrap')



回答3:


It's a late answer but it's worth of answering now. I too faced same problem when a table tr have very big content. I tried the below solution but no luck.

$mpdf->shrink_tables_to_fit=0;

Then I have changed my html structure from table into div, boom it's worked. So now it's working perfectly and the big content is spiting properly between the pages without overlapping header and footer. I hope it will help someone. Cheers




回答4:


<style>
    table {
        overflow: wrap;
    }
</style>


来源:https://stackoverflow.com/questions/26179403/how-to-prevent-table-resizing-in-pdf-using-mpdf-and-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!