表格以pdf显示,只有一个逐行显示

问题描述 投票:0回答:1

我想从一些HTML代码生成一个pdf文档。 html来自sql数据库。 sql内容不是在pdf文档中逐行显示的,而是一行中只有一个字符。

在我的网页上,html代码以所需的方式显示了一个html表格,例如第一列包含sql数据库列名,第二列包含相应的值。例如,第一行应为“ID 158”。在pdf文档中,每行只有一个字符。在前面的例子中,我进入了pdf文档 “一世 d 1 五 8" 。

这是我生成pdf的代码:

// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';
// Create an instance of the class:
try{
  $mpdf = new \Mpdf\Mpdf(['debug' => true]);

// $sub[1] originally comes from the sql database and contains about 70 table rows
$sub[1] = '<table cellpadding="2" cellspacing="0" width="100%"class="print_table one_item"><tr><th ALIGN="LEFT" width="140">ID</th><td ALIGN="LEFT">158</td></tr><tr><th ALIGN="LEFT" width="140">Version Eingabeformular</th><td ALIGN="LEFT">2</td></tr></table>';
$mpdf->WriteHTML('Hello World');
$mpdf->WriteHTML($sub[1]);
// Output a PDF file directly to the browser
$mpdf->Output();

pdf文档应类似于下图:Desired look of pdf document

pdf文档看起来像Real look of pdf document

有人提示我找到合适的解决方案吗?此致,托尔斯滕

mpdf
1个回答
0
投票

我想我修好了。问题是我的表定义的宽度和类属性之间缺少空白。如果我添加空白,它似乎工作正常...

width="100%"**missing blank** class="print_table one_item">
© www.soinside.com 2019 - 2024. All rights reserved.