Lodop云打印控件使用

1,虚拟打印机  迅捷PDF虚拟打印机

学习云打印时可以使用虚拟打印机,省去一些麻烦

下载地址:https://www.jiakaodashi.com/dayinji/downloadsuccess-print.html

 

2,后台网页文件部署相关js类文件

"javascript" src="LodopFuncs.js">

 

3,前端安装lodop程序(注:前端安装的程序要与浏览器的位数一致,而不是与操作系统的位数一致)

下载地址:http://www.lodop.net/download.html

 

4.1,前端代码,前端直接使用

"button" value="打印预览" onclick="prn1_preview()">//点击事件,交互开始

 

var LODOP;

function prn1_preview() {   //被绑定的js函数,调用lodop代码参数

        CreateOneFormPage();    

        if (LODOP.CVERSION) CLODOP.On_Return=function(TaskID,Value){document.getElementById('S1').value=Value;};

        document.getElementById('S1').value="打印预览返回结果:"+LODOP.PREVIEW();

        document.getElementById('id01').disabled = true;    

};

   

function CreateOneFormPage(){   //lodop代码

        MyData=document.getElementById('data01').value; //打印前变量重读一下最新值

        LODOP=getLodop();                 

        LODOP.PRINT_INIT("");

        LODOP.SET_PRINT_MODE("PROGRAM_CONTENT_BYVAR",true);

        LODOP.ADD_PRINT_SETUP_BKIMG("C:\\Users\\Administrator\\Desktop\\新建文件夹\\顺丰5.png");

        LODOP.SET_SHOW_MODE("BKIMG_IN_PREVIEW",true);

        LODOP.ADD_PRINT_TEXT(87,5,274,47,"11111");

  

        LODOP.ADD_PRINT_TEXT(159,9,270,47,"132132131演示变量");

        LODOP.SET_PRINT_STYLEA(0,"ContentVName","MyData");

    };

 

4.2,前端+后台

//前端

var LODOP;

function prn1_preview() {   

        LODOP=getLodop();

        try{

            LODOP.PRINT_INIT("");

 

        }catch(e){

            alert("请先安装打印控件");return;

        }

        var a = [];

        $('.checkLst:checked').each(function(i){

            a.push({name:'id_'+i,value:$(this).val()});

        });

        if(a.length<1){

            alert('请勾选记录');return;

        }

 

        a.push({name:'_order',value:$('#pagerForm input[name="_order"]').val()});

        a.push({name:'_sort',value:$('#pagerForm input[name="_sort"]').val()});

        $.post('__URL__/printLocation',a,function(data){

 

            try{

                eval(data);//将后台返回的json数据作为js代码执行

            /*for(var i in data){

 

                eval(data[i]);

                LODOP.NewPageA();

            }*/

/*        LODOP.SET_PRINT_PAGESIZE(1,600,400,"");

        LODOP.ADD_PRINT_TEXT(3,3,225,25,"库位信息");

        LODOP.SET_PRINT_STYLEA(0,"FontSize",13);

        LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

        LODOP.SET_PRINT_STYLEA(0,"Bold",1);

        LODOP.ADD_PRINT_TEXT(25,3,235,25,"dsaddsad211112111131231231233211");

        LODOP.SET_PRINT_STYLEA(0,"FontSize",10);

        LODOP.ADD_PRINT_TEXT(41,3,235,25,"新加文本3");

        LODOP.SET_PRINT_STYLEA(0,"FontSize",10);

        LODOP.ADD_PRINT_TEXT(58,3,235,25,"新加文本4");

        LODOP.SET_PRINT_STYLEA(0,"FontSize",10);

        LODOP.ADD_PRINT_TEXT(75,3,235,25,"新加文本5");

        LODOP.SET_PRINT_STYLEA(0,"FontSize",10);

        LODOP.ADD_PRINT_TEXT(92,3,235,25,"新加文本6");

        LODOP.SET_PRINT_STYLEA(0,"FontSize",10);

        LODOP.ADD_PRINT_TEXT(109,3,235,25,"新加文本7");

        LODOP.SET_PRINT_STYLEA(0,"FontSize",10);*/

            //console.log(data);

            LODOP.PREVIEW();

            }catch(e){

            alert('未安装打印控件');return;

        }

        });

        //document.getElementById('id01').disabled = true;    

};

 

//后台

   function printLocation()

    {

        $id=I('post.');

        $str=implode(',',$id);

        $model=M("GoodsPosition");

        $data=$model->field('path_part,path_shelves,path_layer,path_grid,goods_no')->where(array('id'=>array("in",$str)))->select();

 

        $lodop='LODOP.SET_PRINT_PAGESIZE(1,600,400,"");LODOP.ADD_PRINT_TEXT(3,3,225,25," 库位信 息");LODOP.SET_PRINT_STYLEA(0,"FontSize",13);LODOP.SET_PRINT_STYLEA(0,"Alignment",2);LODOP.SET_PRINT_STYLEA(0,"Bold",1);';

        $height=3;

        foreach ($data as $key => $v) {

            $height+=17;

            $loc=$v['path_part'].$v['path_shelves'].$v['path_layer'].$v['path_grid'].'#'.$v['goods_no'];

            $lodop.='LODOP.SET_PRINT_STYLEA(0,"FontSize",10);LODOP.ADD_PRINT_TEXT('.$height.',3,235,25,"'.$loc.'");';

        }

 

--------------------------更新---------------------------

因lodop的不兼容性,以及eval()函数可能会被浏览器屏蔽,建议直接在前端使用lodop控件,而且效率更高

HTML代码:

                

            

        

        "vo" name="list">

            "id" rel="{$vo['id']}">

                

"{$vo.path_part}{$vo.path_column}{$vo.path_shelves}{$vo.path_layer}" goods_no="{$vo['goods_no']}" class="checkLst" name="ids" value="{$vo['id']}" type="checkbox">{$vo.path_part}{$vo.path_column}{$vo.path_shelves}{$vo.path_layer} {$vo['goods_no']}

 

jq代码:

//打印库位信息    ---By hc

var LODOP;

function prn1_preview() {   

        LODOP=getLodop();

        LODOP.PRINT_INIT("");

        LODOP.SET_SHOW_MODE("NP_NO_RESULT",true);

        LODOP.SET_PRINT_PAGESIZE(1,600,400,"");

        LODOP.ADD_PRINT_TEXT(3,3,189,25,"库位信息");

        LODOP.SET_PRINT_STYLEA(0,"FontSize",13);

        LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

        LODOP.SET_PRINT_STYLEA(0,"Bold",1);

        LODOP.SET_PRINT_STYLEA(0,"ItemType",1);

        LODOP.SET_PRINT_STYLEA(0,"Horient",2);

                           

        var str='';

         var checks = document.getElementsByName("ids");

        if($('.checkLst:checked').attr('bnno')!='' && $('.checkLst:checked').attr('type')=='checkbox'){

            $('.checkLst:checked').each(function(i){

                var v =    $(this).attr('path')+'#'+ $(this).attr('goods_no');

                if(i"\r\n";}

 

                str += v;

            });

            LODOP.ADD_PRINT_TEXT(27,3,189,100,str);

            LODOP.SET_PRINT_STYLEA(0,"FontSize",11);

            LODOP.SET_PRINT_STYLEA(0,"ItemType",4);

            LODOP.PREVIEW();

        }else{

            alert("请勾选所需打印的鞋码");

        }

};

你可能感兴趣的:(html)