[英]How do i add javascript in TCPDF?
因为我不能使用 css 使用 TCPDF 使用 css 为我的表自动编号。我正在尝试使用 Javascipt 来完成这项工作。 我阅读了有关如何将 javascript 添加到我的 tcpdf 中的文档( this和this )。 但我不知道为什么它不起作用,它显示Parse error: syntax error, unexpected 'var' (T_VAR) in C:\filepath\XAMPP\htdocs\filepath\customerinvoice.php on line 211
如何在 tcpdf 中定义我的“var”? 还是不能在 TCPDF 中添加 javascript? 请帮我解决这个问题。 任何帮助将不胜感激。 提前致谢
这是我的代码
$htmlcontent .='
<table cellpadding="7" style="max-height: 1000px;">
<tr class="receiptcontent">
<td style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
</td>
<td width= "30%" colspan="3" style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
'.$irow['product_name'].'
</td>
<td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
'.$irow['product_code'].'
</td>
<td width= "15%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
'.$irow['quantity'].' '.$irow['quantity_unit'].'
</td>
<td width= "15%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
RM '.$irow['original_price'].'
</td>
<td width= "20%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
RM '.$irow['price'].'
</td>
</tr>
</table>
';
}
这是我添加的 javascript,用于为我的表实现自动编号
$js =
var table = document.getElementsByTagName('table')[0],
rows = table.getElementsByTagName('tr'),
text = 'textContent' in document ? 'textContent' : 'innerText';
for (var i = 0, len = rows.length; i < len; i++) {
rows[i].children[0][text] = i + ': ' + rows[i].children[0][text];
};
// Add Javascript code
$pdf->IncludeJS($js);
$pdf->writeHTML($htmlcontent);
ob_end_clean();
$pdf->Output('customerinvoice.pdf', 'I');
请用双引号将js语句括起来:
改变
$js =
var table = document.getElementsByTagName('table')[0],
rows = table.getElementsByTagName('tr'),
text = 'textContent' in document ? 'textContent' : 'innerText';
for (var i = 0, len = rows.length; i < len; i++) {
rows[i].children[0][text] = i + ': ' + rows[i].children[0][text];
};
至
$js ="
var table = document.getElementsByTagName('table')[0],
rows = table.getElementsByTagName('tr'),
text = 'textContent' in document ? 'textContent' : 'innerText';
for (var i = 0, len = rows.length; i < len; i++) {
rows[i].children[0][text] = i + ': ' + rows[i].children[0][text];
};
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.