我需要打印输出条形码,我在数据表中有项目列表,我有按钮用条形码打印项目详细信息,但有时条形码显示在打印预览中,有些时候不显示在打印预览中。以下是我的代码,
function printitembarcode(barcodeimg, shortname, grosswt, stwt, iscode)
{
if(iscode == 1){
var printContent = "<div><table id='"+ barcodeimg +"' width='300px' height='40px' border='0'><tbody><tr><td width='120px' style='text-align:left;align:left;margin-left:10px !important;'><img src='"+ base_url + "assets/img/barcode/"+ barcodeimg +".png' alt='Bar Code' style='height:37px !important;' /></td><td width='120px' style='font-weight:bold;margin-left:20px;'> CODE : "+ parseInt((stwt)*1000) +"<br>"+ shortname +"<br> Wt : " + grosswt + " Gm </td><td width='60px'></td></tr></tbody></table></div>";
}else{
var printContent = "<div><table id='"+ barcodeimg +"' width='300px' height='40px' border='0'><tbody><tr><td width='120px' style='text-align:left;align:left;margin-left:10px; !important;'><img src='"+ base_url + "assets/img/barcode/"+ barcodeimg+".png' alt='Bar Code' style='height:37px !important;' /></td><td width='120px' style='font-weight:bold;margin-left:20px;'>"+ shortname +"<br> G.Wt : " + grosswt + " Gm <br> S.Wt : "+ stwt + " Gm </td><td width='60px'></td></tr></tbody></table></div>";
}
//console.log(printContent);
var windowUrl = 'about:blank';
var uniqueName = new Date();
var windowName = 'Print' + uniqueName.getTime();
var printWindow = window.open(windowUrl, windowName, 'left=30000,top=30000,width=0,height=0');
printWindow.document.write('<html><head><style type="text/css">@page { size: auto; margin: 0mm; } body { font-family: "Arial Black", "Arial Bold", Gadget, sans-serif; font-size: 11px !important; margin-top: 0px !important; font-weight:bold; } html { margin: 0px; } table{ font-family: "Arial Black", "Arial Bold", Gadget, sans-serif; font-size: 11px !important; margin-left:0px; margin-top:2px;margin-right:1px; border-collapse: collapse; border: 0px solid #ddd; } table td{ height:38px; border: 0px solid #ddd; } table td:first-child { text-align: left; margin-left:2px !important; } p{ margin-top:1px;}@media print{@page { margin: 0mm !important; } font-size: 11px !important; font-weight:bold; table td:first-child { text-align: left;margin-left:2px !important; } } </style></head><body style="font-size: 11px;" onload="window.print()">'+ printContent +'</body></html>');
//printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
我有以下代码在服务器中生成条形码,使用PHP codeigniter
public function set_barcode($code)
{
$this->load->library('zend');
$this->zend->load('Zend/Barcode');
$code = str_pad($code, 6, 0, STR_PAD_LEFT);
$file = Zend_Barcode::draw('code128', 'image', array('text' => $code, 'barHeight' => 25), array());
//$store_image = imagepng($file, $_SERVER['DOCUMENT_ROOT']."/assets/img/barcode/{$code}.png");
$store_image = imagepng($file, $this->config->item('documentroot')."assets/img/barcode/{$code}.png");
}
任何人在没有问题的情况下点击打印按钮时,请帮助任何人显示条形码。现在有时会显示一些时间消失条形码。