我需要更换模板PDF中的条形码,
代码:
using (new SecurityDisabler())
{
DateTime archiveDate = new DateTime(2015, 9, 8);
string pathPrefix = "/sitecore/media library";
// get the recyclebin for the master database
Sitecore.Data.Archiving.Archive archive = Sitecore.Data.Database.GetDatabase("master").Archives["recyclebin"];
// get as many deleted items as possible
// where the archived date is after a given date
// and the item path starts with a given path
var itemsRemovedAfterSomeDate =
archive.GetEntries(0, int.MaxValue)
.Where(entry =>
entry.ArchiveDate > archiveDate &&
entry.OriginalLocation.StartsWith(pathPrefix)
).ToList();
foreach (var itemRemoved in itemsRemovedAfterSomeDate)
{
// restore the item
archive.RestoreItem(itemRemoved.ArchivalId);
}
}
模板HTML:
$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);
答案 0 :(得分:0)
根据TCPDFBarcode documentation文档,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;