我正在设置tcpdf来为客户动态生成发票,但是当我添加图像时,边框正从我的表中消失.这是代码:
/*
if ($status == "Paid") {
$pdf->Image("/wp-content/themes/Feather/images/Paid.jpg", 10, 60, 190, '', '', '', 'T', false, "300", '', false, false, 0, false, false, false);
} elseif ($status == "Overdue") {
$pdf->Image("/wp-content/themes/Feather/images/Overdue.jpg", 10, 60, 190, '', '', '', 'T', false, "300", '', false, false, 0, false, false, false);
} elseif ($status == "Cancelled") {
$pdf->Image("/wp-content/themes/Feather/images/Void.jpg", 10, 60, 190, '', '', '', 'T', false, "300", '', false, false, 0, false, false, false);
}
*/
$pdf->SetXY($x=20, $y=30);
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的HTML:
$html = $html . '
<br/><br/><br/>
<table width="600px" cellspacing="1" cellpadding="4" border="1">
<tr>
<th width="200px">Product</th>
<th width="65px">Code</th>
<th width="65px">Quantity</th>
<th width="65px">Unit Price</th>
<th width="65">VAT Rate</th>
<th width="65">VAT Amount</th>
<th width="65">Line Total</th>
</tr>';
foreach ($inv_lines as $inv_line) {
$html = $html .
'<tr>
<td>' . $inv_line['item_desc'] . '</td>
<td>' . $inv_line['item_no'] . '</td>
<td>' . $inv_line['quantity'] . '</td>
<td>' . $inv_line['unit_price'] . '</td>
<td>' . $inv_line['vat_rate'] . '</td>
<td>' . ($inv_line['quantity'] * $inv_line['vat_rate'] * $inv_line['unit_price'] * 0.01) . '</td>
<td>' . $inv_line['line_total'] . '</td>
</tr>';
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,表格显示正常,但是一旦我取消注释图像位,图像就会出现,但表格边框会消失.我已经尝试为单个单元格添加内联边框,但这不会产生任何影响.
有没有人有任何想法?
EPB*_*EPB 15
首先,绝对确定您始终包含结束表标签.TCPDF的html解析器可能对于打开和关闭标记很挑剔.(我只是说这个,因为它在问题中缺失了.)它依赖于正确的标记来正常运行.
现在我不确定只是通过查看你的坐标,但表格是否与图像重叠?如果确实如此,并且您希望在图像上绘制边框,则需要setPageMark在绘制图像后调用.如果不这样做,无论您使用Image和writeHTML调用的顺序如何,都将在图像下方绘制边框.
<?php
//In my test PDF I had to do something like this as some of my borders
//were disappearing underneath my test image.
$pdf->Image(...);
$pdf->setPageMark();
$pdf->setXY(...)
$pdf->writeHTML(...);
Run Code Online (Sandbox Code Playgroud)
如果边框仍然不存在,这既不是上述帮助,您可能需要在放置图像后尝试设置绘图颜色.我不确定这会做什么,但值得一试.
当然,请确保您使用的是TCPDF的更新版本,具体取决于您的版本,可能存在边框渲染修复.