[英]Write barcode in HTML Template tcpdf
请替换模板PDF中的条形码,
码:
$tmp_product = str_replace("{::prod_price}", $product['price'], $tmp_product);
$eancodes = $product['ean'];
$eancode = new TCPDFBarcode($eancodes, 'EAN13');
$tmp_product = str_replace("{::prod_ean}", $eancode, $tmp_product);
模板HTML:
define('PDF_TEMPLATE_PROD', '
<tr class="pdf_prod" id="{::prod_name}" nobr="true">
<td class="pdf_prod_desc">
<ul class="pdf_prod_ul">
<li><strong>{::txt_prod_price}</strong> {::prod_price}</li>
<li class="pdf_prod_bcode">{::prod_ean}</li>
</ul>
</td>
</tr>
');
根据TCPDFBarcode文档文档, TCPDFBarcode
类为您提供了一种可用于显示条形码的方法:
getBarcodeHTML
返回条形码的HTML表示形式。 您可以将此HTML直接插入PDF_TEMPLATE_PROD
模板中 使用getBarcodeHTML
方法,您可以执行以下操作:
// define the HTML template you'll use to markup the product data
define('PDF_TEMPLATE_PROD', '
<tr class="pdf_prod" id="{::prod_name}" nobr="true">
<td class="pdf_prod_desc">
<ul class="pdf_prod_ul">
<li><strong>{::txt_prod_price}</strong> {::prod_price}</li>
<li class="pdf_prod_bcode">{::prod_ean}</li>
</ul>
</td>
</tr>
');
// pass the template into a variable where you'll fill in the data
$tmp_product = constant('PDF_TEMPLATE_PROD');
// insert the price
$tmp_product = str_replace("{::prod_price}", $product['price'], $tmp_product);
// extract the data you want to encode and create your TCPDFBarcode object:
$eancodes = $product['ean'];
$eancode = new TCPDFBarcode($eancodes, 'EAN13');
// insert the HTML represenation of the barcode and print the result
$tmp_product = str_replace("{::prod_ean}", $eancode->getBarcodeHTML(), $tmp_product);
echo $tmp_product;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.