我想并排显示两张桌子。我的html显示正确的结果但是当我使用TCpdf将html更改为pdf时,表格并没有并排显示,因为TCPDF不支持float属性。请告诉我如何使用tcpdf并排显示表格。我的html如下
<table style="float:left">
<tr>
<td>
</td>
</tr>
</table>
<table style="float"left">
<tr>
<td>
</td>
</tr>
</table>
答案 0 :(得分:0)
其中一种方法是拿一张桌子,在每张桌子里放两张桌子。所以输出将是
<?php
require_once('tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 048');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 048', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', 'B', 20);
// add a page
$pdf->AddPage();
$pdf->Write(0, 'Example of side by sideHTML tables', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetFont('helvetica', '', 8);
$tbl='<table>
<tr>
<td>
<table cellspacing="0" cellpadding="1" border="1" style="float:right;width:300px">
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>
</td>
<td>
<table cellspacing="0" cellpadding="1" border="1" style="float:right;width:300px">
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
</td>
</tr>
</table>
';
$pdf->writeHTML($tbl, true, false, false, false, '');
//Close and output PDF document
$pdf->Output('example_048.pdf', 'I');
?>
答案 1 :(得分:0)
显然,TCPDF在设置两个div或表彼此相邻以及可能还有许多其他元素方面存在一些问题,因此CSS不会解决问题。因此,不必理会样式,浮动和宽度(?),而是将表放在另一个表中,例如Deep 3015的答案。我对此不确定,但是我确定HTML2PDF实现了很多TCPDF中不可用的CSS(由于HTML2PDF基于TCPDF,所以很好),只是saiyan。
答案 2 :(得分:0)
请尽力使用下面的代码,即使无法做到最好
<table style="padding-top: 10px;">
<tr style="font-size:11px;">
<td>
<table border="1" cellpadding="1" cellspacing="0" style="width:100%">
<tr>
<th bgcolor="#BDD6EE" colspan="2"
style="height:20px; text-align: center;vertical-align: middle;"><strong>ADMISSION
PACKAGE 2019</strong>
</th>
</tr>
<tr>
<td style="width:80%; text-align: center;">Half of CEA License Fee</td>
<td style="width:20%;text-align: center;">$115.00</td>
</tr>
<tr>
<td style="text-align: center;">CEA Application Fee</td>
<td style="text-align: center;">$53.50</td>
</tr>
<tr>
<td style="text-align: center;">Professional Indemnity Premium (Blanket)</td>
<td style="text-align: center;">$139.00</td>
</tr>
<tr>
<td style="text-align: center;">Convention Package</td>
<td style="text-align: center;">$128.00</td>
</tr>
<tr>
<td style="text-align: center;">Estate Agent Card</td>
<td style="text-align: center;">$20.00</td>
</tr>
<tr>
<td style="text-align: right;"><b>TOTAL:</b> </td>
<td style="text-align: center;"><b>$455.50</b></td>
</tr>
</table>
</td>
<td>
<table border="1" cellpadding="1" cellspacing="0" style="width:100%">
<tr>
<th bgcolor="#BDD6EE" colspan="2"
style="height:20px; text-align: center;vertical-align: middle;"><strong>RENEWAL PACKAGE
2020</strong>
</th>
</tr>
<tr>
<td style="width:80%; text-align: center;">CEA License Fee</td>
<td style="width:20%; text-align: center;">$230.00</td>
</tr>
<tr>
<td style="text-align: center;">Professional Indemnity Premium (Blanket)</td>
<td style="text-align: center;">$139.00</td>
</tr>
<tr>
<td style="text-align: center;">Convention Package</td>
<td style="text-align: center;">$128.00</td>
</tr>
<tr>
<td style="text-align: right;"><b>TOTAL:</b> </td>
<td style="text-align: center;"><b>$497.00</b></td>
</tr>
</table>
</td>
</tr>