微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 TCPDF 中添加 javascript?

如何解决如何在 TCPDF 中添加 javascript?

因为我不能使用 css 使用 TCPDF 为我的表格自动编号,我正在尝试使用 Javascipt 来完成这项工作。我阅读了有关如何将 javascript 添加到我的 tcpdf 中的文档(thisthis)。但我不知道为什么它不起作用,它显示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],len = rows.length; i < len; i++) {
  rows[i].children[0][text] = i + ': ' + rows[i].children[0][text];
};
"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。