1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 芯烨网口小票打印机 使用PHP打印小票

芯烨网口小票打印机 使用PHP打印小票

时间:2019-11-01 01:12:27

相关推荐

芯烨网口小票打印机 使用PHP打印小票

php扩展安装

mbstring

apt install php7.3-mbstring

imagick

apt install php7.3-imagick

<?php//esc/pos打印机指令const ESC="\x1b";//设置const GS="\x1d";//页面设置 字体大小17倍数const HT="\x09";//跳格设置 9,17,25,33,41const CUT="\x1d";//切纸const LF="\x0a";//打印缓冲区并换行//网口小票打印机IP,连接端口const PRINTER_IP="192.168.1.150";const PRINTER_PORT="9100";//图片打印数据生成function toRasterFormat($im){$im->setFormat('pbm');$blob=$im->getImageBlob();$i=strpos($blob,"\n",3);return substr($blob,$i+1);}//图片打印数据头生成function intLowHigh($input, $length){$outp="";for($i=0;$i<$length;$i++){$outp.=chr($input%256);$input=(int)($input/256);}return $outp;}//二唯码图片打印数据$im=new Imagick();$im->setResourceLimit(6,1);$im->readimage("/var/www/bluesky/wg/img/code.jpg");//图片路径$widthBytes=(int)(($im->getimagewidth()+7)/8);$heightPixels=$im->getimageheight();$print_code=GS."v0".chr(0).intLowHigh($widthBytes,2).intLowHigh($heightPixels,2).toRasterFormat($im);$fp=@fsockopen(PRINTER_IP,PRINTER_PORT,$errno,$errstr,60);if($fp===false){//连接打印机出错die($errstr);}else{fwrite($fp,ESC."@");//初始化fwrite($fp,GS."!".chr(17));fwrite($fp,iconv("UTF-8","GBK//IGNORE","单号:A001"));fwrite($fp,LF);fwrite($fp,iconv("UTF-8","GBK//IGNORE","日期:-06-18"));fwrite($fp,LF);fwrite($fp,iconv("UTF-8","GBK//IGNORE","手机:13682890593"));fwrite($fp,LF);fwrite($fp,iconv("UTF-8","GBK//IGNORE","地址:ABC"));fwrite($fp,LF);fwrite($fp,GS."!".chr(0)); fwrite($fp,"------------------------------------------------");fwrite($fp,iconv("UTF-8","GBK//IGNORE","名称/规格"));fwrite($fp,HT);fwrite($fp,HT);fwrite($fp,HT);fwrite($fp,iconv("UTF-8","GBK//IGNORE","单价"));fwrite($fp,HT);fwrite($fp,iconv("UTF-8","GBK//IGNORE","数量"));fwrite($fp,HT);$mc="你的产品名称与规格";$i=0;$sl=mb_strlen($mc);while($sl>$i+16){fwrite($fp,iconv("UTF-8","GBK//IGNORE",mb_substr($mc,$i,16)));fwrite($fp,LF);$i+=16;}fwrite($fp,iconv("UTF-8","GBK//IGNORE",mb_substr($mc,$i,16)));$sl=ceil(mb_strwidth(mb_substr($mc,$i,16))/2);$i=floor((16-$sl)/4)+1; while($i>0){fwrite($fp,HT);$i--;}fwrite($fp,iconv("UTF-8","GBK//IGNORE"," 69.52"));//你的产品单价fwrite($fp,HT);fwrite($fp,iconv("UTF-8","GBK//IGNORE"," 5"));//数量fwrite($fp,LF);fwrite($fp,"------------------------------------------------");fwrite($fp,GS."!".chr(17));fwrite($fp,iconv("UTF-8","GBK//IGNORE","合计:¥200.01"));fwrite($fp,LF);fwrite($fp,"------------------------");fwrite($fp,ESC."a".chr(1));//居中fwrite($fp,$print_code);//打印二唯码图片fwrite($fp,LF);fwrite($fp,iconv("UTF-8","GBK//IGNORE","欢迎下次惠顾"));fwrite($fp,ESC."d".chr(5));//走行fwrite($fp,CUT."V".chr(0).chr(2));//切纸//关闭打印机连接fclose($fp);}?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。