如何防止使用mPDF和PHP调整PDF中的表格大小? [英] How to prevent table resizing in PDF using mPDF and PHP?

查看:191
本文介绍了如何防止使用mPDF和PHP调整PDF中的表格大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些表格数据,提交后会生成PDF。问题是PDF中表格的大小。如果我的表单中的某些字符串太长,则会错误地生成PDF。这是因为桌子。它们具有静态大小,因此如果字符串太长,表将无法容纳它。我使用mPDF库。

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?

如果字符串{p}最长,则表的宽度减小。我想如果字符串{p}比表的宽度最长,那么{p}应该在下一行写出,表的高度应该增加。

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:

以下是mPDF的代码片段:

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;

HTML表格的片段:

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>


推荐答案

此处:

<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">

看看会发生什么。

这篇关于如何防止使用mPDF和PHP调整PDF中的表格大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆