php 生成条形码打印

/**
 * 128 条形码
 * @param $content
 * @param $path
 * @param $scale
 * @param $thickness
 * @throws \BCGDrawException
 */
public function create_barcode2($content,$path,$scale,$thickness){
//根据运单号生成条形码
    $color_black = new \BCGColor(0, 0, 0);
    $color_white = new \BCGColor(255, 255, 255);

    $drawException = null;
    try
    {
        $code = new \BCGcode128();
        $code->setScale($scale);
        $code->setThickness($thickness); // 条形码的厚度
        $code->setForegroundColor($color_black); // 条形码颜色
        $code->setBackgroundColor($color_white); // 空白间隙颜色
// $code->setFont($font); //
        $code->parse($content); // 条形码需要的数据内容
    }
    catch(\Exception $exception)
    {
        $drawException = $exception;
    }


//根据以上条件绘制条形码
    $drawing = new \BCGDrawing($path, $color_white);

    if($drawException) {
        $drawing->drawException($drawException);
    }else{
        $drawing->setBarcode($code);
        $drawing->draw();
    }

// 生成PNG格式的图片
    header('Content-Type: image/jpeg');
// header('Content-Disposition:attachment; filename="barcode.png"'); //自动下载
    $drawing->finish(\BCGDrawing::IMG_FORMAT_JPEG);
//$path = $this->create_barcode($content['yundanhao']);

}



public function print_label_code1(){

    $id = $this->request->get('id');
    $into_store_goods =Db::table('wh_into_store_goods')->where('id',$id)->find();
    $im = imagecreatetruecolor(600,180); // 设置画布/
    $font= EXTEND_PATH.'/CreateImg/hanwenziti/fangzhengheiti.ttf';
    $bgColor = imagecolorallocate($im, 255, 255, 255); // 颜色
    imagefill($im,0,0,$bgColor);
    $blacka = imagecolorallocate($im, 0, 0, 0); // 颜色

    $path1 = ROOT_PATH .'/public/uploads/images/'.create_guid().'no_1.jpg';
    $this->create_barcode2($into_store_goods['label_code'],$path1,2,25);
    $src_img1 = imagecreatefromjpeg($path1);
    $src_w1 = imagesx($src_img1);
    $src_h1 = imagesy($src_img1);
    $image1 = file_get_contents($path1);
    $images1 = substr_replace($image1,pack("Cnn",0x01,300,300),13,5);
    file_put_contents($path1,$images1);
    imagecopy($im,$src_img1,80,110,0,0,$src_w1,$src_h1);

    $path2 = ROOT_PATH .'/public/uploads/images/'.create_guid().'no_2.jpg';
    $this->create_barcode2( str_replace(' ', '',$into_store_goods['sku_code']),$path2,1,50);
    $src_img2 = imagecreatefromjpeg($path2);
    $src_w2 = imagesx($src_img2);
    $src_h2 = imagesy($src_img2);
    $image2 = file_get_contents($path2);
    $images2 = substr_replace($image2,pack("Cnn",0x01,300,300),13,5);
    file_put_contents($path2,$images2);
    imagecopy($im,$src_img2,80,20,0,0,$src_w2,$src_h2);




    $path44 = '/uploads/images/'.create_guid().'no_4.jpg';
    $path4 = ROOT_PATH .'/public'.$path44;
    imagejpeg($im, $path4);
    $image4 = file_get_contents($path4);
    $images4 = substr_replace($image4,pack("Cnn",0x01,300,300),13,5);
    file_put_contents($path4,$images4);
    imagedestroy($im); // 销毁图片
    unlink($path1);
    unlink($path2);
    $this->assign("path",$path44);
    $this->view->engine->layout(false);
    return $this->fetch("img_large_no");
}
<script src="__CDN__/assets/js/html5shiv.js"></script>
<script src="__CDN__/assets/js/jquery.jqprint-0.3.js"></script>
<script src="__CDN__/assets/js/jquery.min.js?v={:config('asset_version')}"></script>
<script src="__CDN__/assets/js/jquery.PrintArea.js?v={:config('asset_version')}"></script>
<body>

<div align="center">
<div><button type="button" id="button" name="print" class="btn btn-minw btn-primary" style=" margin-top: 60px; margin-bottom: 60px;
width: 109px;
height: 55px;"><b><h4>打印</h4></b></button></div>
<div id="img_content">
<img src="{$path}" style="width:600px; height:180px"></div>
</div>
<input type="hidden" id ="path" value="{$path}"/>
</body>
<script>
$("#button").click(function(){
//$("#img_content").printArea();
$("#button").attr("style","display:none");

window.print();
setTimeout("",0);
var path = $("#path").val();
$.ajax({
url: "{:url('deletepath')}",
type: "post",
data: {'path': path},
dataType: "json",
success: function (result) {
if(result.code == 1){
window.opener=null;
window.open('','_self');
window.close();
}
}
})
})
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浮生若梦01

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值