溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

js調(diào)用HttpPrinter(web打印插件)

發(fā)布時(shí)間:2020-08-05 19:42:10 來(lái)源:網(wǎng)絡(luò) 閱讀:1811 作者:51cccaotu 欄目:web開(kāi)發(fā)

js調(diào)用HttpPrinter(web打印插件)

對(duì)比了 康虎云報(bào)表 lodop 后 選擇了 HttpPrinter (原因: 功能免費(fèi) 只有源碼收費(fèi))

demo地址:
https://www.lanzous.com/b743805

js代碼如下,base64的部分已經(jīng)精簡(jiǎn):

<!DOCTYPE html>
<html>
<head>

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

<script>

$(document).ready(function(){

//獲取打印機(jī)列表 begin
$("#btn_getprintlist").click(function(){
var ip = $("#ip").val();
var port = $("#port").val();

if(ip==""||port==""){alert("ip,port不能為空"); return false;}

//$.post("http://127.0.0.1:12345/getprinterlist",
$.post("http://"+ip+":"+port+"/getprinterlist",
{
  //method:"Donald Duck",
  //city:"Duckburg"
},
function(data){
    data = decodeURIComponent(data);
    //alert(data);

    if(data==""){
        alert("連接HttpPrinter失敗");
    }else{
        //alert(data);
        var obj = JSON.parse(data);
        //alert(obj.status);

        $("#PrinterS").empty();

        if(obj.status=="ok"){
            alert("獲取成功");

            //

            //$("#PrinterS").append("<option value='"+obj.sites[1].name +"'>"+obj.sites[1].name +"</option>"); 
            for(var o in obj.data){  
                //alert(o);  
                //alert(obj.data[o]);  
                var printname = obj.data[o].name;
                //alert(printname);
                $("#PrinterS").append("<option value='"+printname +"'>"+printname +"</option>"); 
             }  

        }else{
            alert("獲取失敗:"+obj.data);
        }
        //console.log(data);

    }
});

});
//獲取打印機(jī)列表 end

//打印測(cè)試報(bào)表 begin
$("#btn_printtest").click(function(){
var ip = $("#ip").val();
var port = $("#port").val();

if(ip==""||port==""){alert("ip,port不能為空"); return false;}

$.post("http://"+ip+":"+port+"/printreport",
{
  "ReportName": encodeURIComponent("test.grf"),     /*報(bào)表文件名 測(cè)試報(bào)表 */
  "ReportVersion": 1,              /*可選。報(bào)表版本, 為空則默認(rèn)1  如果本地報(bào)表的版本過(guò)低 將從 ReportUrl 地址進(jìn)行下載更新*/
  //"ReportUrl": encodeURIComponent("http://localhost:9099/report/test.grf"),                  /*可選。為空 將不更新本地報(bào)表 , 如果本地報(bào)表不存在可以從該地址自動(dòng)下載*/
  "ReportUrl": encodeURIComponent("http://111.67.202.157:9099/report/test.grf"),                  /*可選。為空 將不更新本地報(bào)表 , 如果本地報(bào)表不存在可以從該地址自動(dòng)下載*/

  "Copies": 1,                    /*可選。打印份數(shù),支持指定打印份數(shù)。默認(rèn)1份,如果為零,不打印,只返回報(bào)表生成的pdf,jpg等文件*/
  "PrinterName": encodeURIComponent($("#PrinterS option:selected").text()),      /*可選。指定打印機(jī),為空的話 使用默認(rèn)打印機(jī), 請(qǐng)?jiān)?控制面板 -> 設(shè)備和打印機(jī) 中查看您的打印機(jī)的名稱 */
  "PrintOffsetX": 0,                 /*可選。打印右偏移,單位厘米。報(bào)表的水平方向上的偏移量,向右為正,向左為負(fù)。*/
  "PrintOffsetY": 0,                /*可選。打印下偏移,單位厘米。 報(bào)表的垂直方向上的偏移量,向下為正,向上為負(fù)。*/
  "Preview": 0,                 /*可選。是否預(yù)覽,和主界面設(shè)置的效果一樣 為空默認(rèn)不預(yù)覽,   0:不預(yù)覽,1:預(yù)覽(彈出導(dǎo)出的pdf,jpg等文件)。*/
  "token": encodeURIComponent("aa"),      /*可選。只要token值在列表中 方可打印*/

  "Control": encodeURIComponent('['  ///*部件框,可選值:AsStaticBox ,AsMemoBox,AsRichTextBox,AsPictureBox (base64格式),AsBarcode*/
    +'{"type": "AsStaticBox", "name": "姓名","value": "高文杰","required": false},'
    +'{"type": "AsStaticBox", "name": "性別","value": "男","required": false},'
    +'{"type": "AsStaticBox", "name": "電話","value": "13165191728","required": false},'
    +'{"type": "AsBarcode", "name": "二維碼","value": "5520002701774727","required": false},'
    +'{"type": "AsPictureBox", "name": "圖片","value": "/9j/4AAQSkZJRgABgAooooA/9k=","required": false},'  //base64格式
    +']'),

  "Parameter": encodeURIComponent('['  ///*參數(shù),type 默認(rèn)為空即可,已經(jīng)在報(bào)表端設(shè)置了 備用字段  
    +'{"type": "", "name": "單號(hào)","value": "5520002701774727","required": false},'
    +'{"type": "", "name": "日期","value": "2019-09-09 12:21:12","required": false},'
    +'{"type": "", "name": "year","value": "2018","required": false},'
    +']'),

  "Field": encodeURIComponent('['  ///*字段, type ftBlob (base64格式) ,ftString ftInteger ftBoolean, ftFloat, ftCurrency,ftDateTime,  size (ftString 設(shè)置為實(shí)際長(zhǎng)度,其他的設(shè)置為0,例如 ftInteger ftBlob 等設(shè)置為0 ) 
    +'{"type": "ftString", "name": "快遞單號(hào)","size": 255,"required": true},'
    +'{"type": "ftString", "name": "發(fā)件人","size": 255,"required": false},'
    +'{"type": "ftString", "name": "發(fā)件人電話","size": 255,"required": false},'
    +'{"type": "ftBlob", "name": "圖像","size": 0,"required": false},'
    +']'),

  "Data": encodeURIComponent('['  ///*數(shù)據(jù)行  
    +'{"快遞單號(hào)": "1234567890", "發(fā)件人": "山東易橋智能科技有限公司","發(fā)件人電話": "13165191728","圖像": "/9j/4AAQSkZJRgABAQEAYABgAAAKKKKACiiigAooooA/9k="},'
    +'{"快遞單號(hào)": "1234567890", "發(fā)件人": "山東易橋智能科技有限公司","發(fā)件人電話": "13165191728","圖像": "/9j/4AAQSkZJRgABAQEAYABgAAAKKKKACiiigAooooA/9k="},'
    +'{"快遞單號(hào)": "1234567890", "發(fā)件人": "山東易橋智能科技有限公司","發(fā)件人電話": "13165191728","圖像": "/9j/4AAQSkZJRgABAQEAYABgAAAKKKKACiiigAooooA/9k="},'
    +'{"快遞單號(hào)": "1234567890", "發(fā)件人": "山東易橋智能科技有限公司","發(fā)件人電話": "13165191728","圖像": "/9j/4AAQSkZJRgABAQEAYABgAAAKKKKACiiigAooooA/9k="},'
    +'{"快遞單號(hào)": "1234567890", "發(fā)件人": "山東易橋智能科技有限公司","發(fā)件人電話": "13165191728","圖像": "/9j/4AAQSkZJRgABAQEAYABgAAAKKKKACiiigAooooA/9k="},'
    +'{"快遞單號(hào)": "1234567890", "發(fā)件人": "山東易橋智能科技有限公司","發(fā)件人電話": "13165191728","圖像": "/9j/4AAQSkZJRgABAQEAYABgAAAKKKKACiiigAooooA/9k="},'
    +']'),

},
function(data){
    data = decodeURIComponent(data);
    //alert(data);

    if(data==""){
        alert("連接HttpPrinter失敗");
    }else{
        //alert(data);
        var obj = JSON.parse(data);
        //alert(obj.status);

        if(obj.status=="ok"){
            alert("打印成功");

            //

        }else{
            alert("打印失敗:"+obj.data);
        }
        //console.log(data);

    }
});

});
//打印測(cè)試報(bào)表 end

//打印條形碼 begin
$("#btn_barcode").click(function(){
var ip = $("#ip").val();
var port = $("#port").val();

if(ip==""||port==""){alert("ip,port不能為空"); return false;}

//$.post("http://127.0.0.1:12345/getprinterlist",
$.post("http://"+ip+":"+port+"/printreport",
{
  "ReportName": encodeURIComponent("barcode.grf"),     /*報(bào)表文件名 條形碼 */
  "ReportVersion": 1,              /*可選。報(bào)表版本, 為空則默認(rèn)1  如果本地報(bào)表的版本過(guò)低 將從 ReportUrl 地址進(jìn)行下載更新*/
  "ReportUrl": encodeURIComponent("http://111.67.202.157:9099/report/barcode.grf"),                  /*可選。為空 將不更新本地報(bào)表 , 如果本地報(bào)表不存在可以從該地址自動(dòng)下載*/
  "Copies": 1,                  /*可選。打印份數(shù),支持指定打印份數(shù)。默認(rèn)1份,如果為零,不打印,只返回報(bào)表生成的pdf,jpg等文件*/
  "PrinterName": encodeURIComponent($("#PrinterS option:selected").text()),      /*可選。指定打印機(jī),為空的話 使用默認(rèn)打印機(jī), 請(qǐng)?jiān)?控制面板 -> 設(shè)備和打印機(jī) 中查看您的打印機(jī)的名稱 */
  "PrintOffsetX": 0,                 /*可選。打印右偏移,單位厘米。報(bào)表的水平方向上的偏移量,向右為正,向左為負(fù)。*/
  "PrintOffsetY": 0,                /*可選。打印下偏移,單位厘米。 報(bào)表的垂直方向上的偏移量,向下為正,向上為負(fù)。*/
  "token": encodeURIComponent("aa"),      /*可選。只要token值在列表中 方可打印*/

  "Field": encodeURIComponent('['  ///*字段, type ftBlob (base64格式) ,ftString ftInteger ftBoolean, ftFloat, ftCurrency,ftDateTime,  size (ftString 設(shè)置為實(shí)際長(zhǎng)度,其他的設(shè)置為0,例如 ftInteger ftBlob 等設(shè)置為0 ) 
    +'{"type": "ftString", "name": "name","size": 255,"required": true},'
    +'{"type": "ftString", "name": "no","size": 255,"required": false},'
    +']'),

  "Data": encodeURIComponent('['  ///*數(shù)據(jù)行  
    +'{"name": "劉一", "no": "001"},'
    +'{"name": "陳二","no": "002"},'
    +'{"name": "張三","no": "003"},'
    +'{"name": "李四","no": "004"},'
    +'{"name": "王五","no": "005"},'
    +'{"name": "趙六","no": "006"},'
    +'{"name": "孫七","no": "007"},'
    +'{"name": "周八","no": "008"},'
    +'{"name": "吳九","no": "009"},'
    +'{"name": "鄭十","no": "010"},'
    +']'),

},
function(data){
    data = decodeURIComponent(data);
    //alert(data);

    if(data==""){
        alert("連接HttpPrinter失敗");
    }else{
        //alert(data);
        var obj = JSON.parse(data);
        //alert(obj.status);

        if(obj.status=="ok"){
            alert("打印成功");

            //

        }else{
            alert("打印失敗:"+obj.data);
        }
        //console.log(data);

    }
});

});
//打印條形碼 end

//打印Pos小票 begin
$("#btn_pos").click(function(){
var ip = $("#ip").val();
var port = $("#port").val();

if(ip==""||port==""){alert("ip,port不能為空"); return false;}

$.post("http://"+ip+":"+port+"/printreport",
{
  "ReportName": encodeURIComponent("PosTicket.grf"),     /*報(bào)表文件名 POS小票 */
  "ReportVersion": 1,              /*可選。報(bào)表版本, 為空則默認(rèn)1  如果本地報(bào)表的版本過(guò)低 將從 ReportUrl 地址進(jìn)行下載更新*/
  "ReportUrl": encodeURIComponent("http://111.67.202.157:9099/report/PosTicket.grf"),                  /*可選。為空 將不更新本地報(bào)表 , 如果本地報(bào)表不存在可以從該地址自動(dòng)下載*/
  "Copies": 1,                  /*可選。打印份數(shù),支持指定打印份數(shù)。默認(rèn)1份,如果為零,不打印,只返回報(bào)表生成的pdf,jpg等文件*/
  "PrinterName": encodeURIComponent($("#PrinterS option:selected").text()),      /*可選。指定打印機(jī),為空的話 使用默認(rèn)打印機(jī), 請(qǐng)?jiān)?控制面板 -> 設(shè)備和打印機(jī) 中查看您的打印機(jī)的名稱 */
  "PrintOffsetX": 0,                 /*可選。打印右偏移,單位厘米。報(bào)表的水平方向上的偏移量,向右為正,向左為負(fù)。*/
  "PrintOffsetY": 0,                /*可選。打印下偏移,單位厘米。 報(bào)表的垂直方向上的偏移量,向下為正,向上為負(fù)。*/
  "token": encodeURIComponent("aa"),      /*可選。只要token值在列表中 方可打印*/

  "Parameter": encodeURIComponent('['  ///*參數(shù),type 默認(rèn)為空即可,已經(jīng)在報(bào)表端設(shè)置了 備用字段  
    +'{"type": "", "name": "title","value": "易橋餐廳消費(fèi)小票","required": false},'
    +'{"type": "", "name": "SubTitle","value": "官方網(wǎng)站:http://www.yiqiao.net.cn","required": false},'
    +'{"type": "", "name": "deskname","value": "桌號(hào):1001","required": false},'
    +'{"type": "", "name": "djh","value": "單據(jù)號(hào):20191101000001","required": false},'
    +'{"type": "", "name": "czy","value": "操作員:高文杰","required": false},'
    +'{"type": "", "name": "starttime","value": "消費(fèi)日期:2019-11-01","required": false},'
    +'{"type": "", "name": "tf","value": "","required": false},'
    +'{"type": "", "name": "ysje","value": "100.00","required": false},'
    +'{"type": "", "name": "yhje","value": "0.00","required": false},'
    +'{"type": "", "name": "sjje","value": "100.00","required": false},'
    +'{"type": "", "name": "kahao","value": "890001","required": false},'
    +']'),    

  "Field": encodeURIComponent('['  ///*字段, type ftBlob (base64格式) ,ftString ftInteger ftBoolean, ftFloat, ftCurrency,ftDateTime,  size (ftString 設(shè)置為實(shí)際長(zhǎng)度,其他的設(shè)置為0,例如 ftInteger ftBlob 等設(shè)置為0 ) 
    +'{"type": "ftString", "name": "shangpname","size": 255,"required": true},'
    +'{"type": "ftString", "name": "shuliang","size": 255,"required": false},'
    +'{"type": "ftString", "name": "je","size": 255,"required": false},'
    +']'),

  "Data": encodeURIComponent('['  ///*數(shù)據(jù)行  
    +'{"shangpname": "青椒肉絲", "shuliang": "1", "je": "14.50"},'
    +'{"shangpname": "清湯丸子", "shuliang": "1", "je": "20.90"},'
    +'{"shangpname": "土豆絲", "shuliang": "1", "je": "7.00"},'
    +'{"shangpname": "涼拌牛肉", "shuliang": "1", "je": "50.00"},'
    +'{"shangpname": "紅燒茄子", "shuliang": "1", "je": "30.00"},'
    +'{"shangpname": "四喜丸子", "shuliang": "1", "je": "23.00"},'
    +'{"shangpname": "溜肥腸", "shuliang": "1", "je": "30.00"},'
    +'{"shangpname": "炒年糕", "shuliang": "1", "je": "33.00"},'
    +'{"shangpname": "燒鵝掌", "shuliang": "1", "je": "34.00"},'
    +'{"shangpname": "螞蟻上樹(shù)", "shuliang": "1", "je": "65.00"},'
    +']'),

},
function(data){
    data = decodeURIComponent(data);
    //alert(data);

    if(data==""){
        alert("連接HttpPrinter失敗");
    }else{
        //alert(data);
        var obj = JSON.parse(data);
        //alert(obj.status);

        if(obj.status=="ok"){
            alert("打印成功");

            //

        }else{
            alert("打印失敗:"+obj.data);
        }
        //console.log(data);

    }
});

});
//打印Pos小票 end

//打印客戶基本信息 begin
$("#btn_customer").click(function(){
var ip = $("#ip").val();
var port = $("#port").val();

if(ip==""||port==""){alert("ip,port不能為空"); return false;}

$.post("http://"+ip+":"+port+"/printreport",
{
  "ReportName": encodeURIComponent("customer.grf"),     /*報(bào)表文件名 客戶基本信息 */
  "ReportVersion": 1,              /*可選。報(bào)表版本, 為空則默認(rèn)1  如果本地報(bào)表的版本過(guò)低 將從 ReportUrl 地址進(jìn)行下載更新*/
  "ReportUrl": encodeURIComponent("http://111.67.202.157:9099/report/customer.grf"),                  /*可選。為空 將不更新本地報(bào)表 , 如果本地報(bào)表不存在可以從該地址自動(dòng)下載*/
  "Copies": 1,                  /*可選。打印份數(shù),支持指定打印份數(shù)。默認(rèn)1份,如果為零,不打印,只返回報(bào)表生成的pdf,jpg等文件*/
  "PrinterName": encodeURIComponent($("#PrinterS option:selected").text()),      /*可選。指定打印機(jī),為空的話 使用默認(rèn)打印機(jī), 請(qǐng)?jiān)?控制面板 -> 設(shè)備和打印機(jī) 中查看您的打印機(jī)的名稱 */
  "PrintOffsetX": 0,                 /*可選。打印右偏移,單位厘米。報(bào)表的水平方向上的偏移量,向右為正,向左為負(fù)。*/
  "PrintOffsetY": 0,                /*可選。打印下偏移,單位厘米。 報(bào)表的垂直方向上的偏移量,向下為正,向上為負(fù)。*/
  "token": encodeURIComponent("aa"),      /*可選。只要token值在列表中 方可打印*/

  "Field": encodeURIComponent('['  ///*字段, type ftBlob (base64格式) ,ftString ftInteger ftBoolean, ftFloat, ftCurrency,ftDateTime,  size (ftString 設(shè)置為實(shí)際長(zhǎng)度,其他的設(shè)置為0,例如 ftInteger ftBlob 等設(shè)置為0 ) 
    +'{"type": "ftString", "name": "CustomerID","size": 255,"required": true},'
    +'{"type": "ftString", "name": "CompanyName","size": 255,"required": false},'
    +'{"type": "ftString", "name": "ContactName","size": 255,"required": false},'
    +'{"type": "ftString", "name": "ContactTitle","size": 255,"required": false},'
    +'{"type": "ftString", "name": "Address","size": 255,"required": false},'
    +'{"type": "ftString", "name": "City","size": 255,"required": false},'
    +'{"type": "ftString", "name": "Region","size": 255,"required": false},'
    +'{"type": "ftString", "name": "PostalCode","size": 255,"required": false},'
    +'{"type": "ftString", "name": "Country","size": 255,"required": false},'
    +'{"type": "ftString", "name": "Phone","size": 255,"required": false},'
    +'{"type": "ftString", "name": "Fax","size": 255,"required": false},'
    +']'),

  "Data": encodeURIComponent('['  ///*數(shù)據(jù)行  
    +'{"CustomerID": "SDYQKJ", "CompanyName": "易橋科技", "ContactName": "高文杰", "ContactTitle": "經(jīng)理", "Address": "商動(dòng)力大廈", "City": "濟(jì)寧", "Region": "華東", "PostalCode": "272100", "Country": "中國(guó)", "Phone": "13165191728", "Fax": "0537-2345660"},'
    +'{"CustomerID": "CHOPS", "CompanyName": "浩天旅行社", "ContactName": "方先生", "ContactTitle": "經(jīng)理", "Address": "白廣路 314 號(hào)", "City": "天津", "Region": "華北", "PostalCode": "234254", "Country": "中國(guó)", "Phone": "(030) 30076545", "Fax": ""},'
    +'{"CustomerID": "SEVES", "CompanyName": "艾德高科技", "ContactName": "謝×××", "ContactTitle": "經(jīng)理", "Address": "起義路 231 號(hào)", "City": "天津", "Region": "華北", "PostalCode": "013072", "Country": "中國(guó)", "Phone": "(030) 55657717", "Fax": ""},'
    +']'),

},
function(data){
    data = decodeURIComponent(data);
    //alert(data);

    if(data==""){
        alert("連接HttpPrinter失敗");
    }else{
        //alert(data);
        var obj = JSON.parse(data);
        //alert(obj.status);

        if(obj.status=="ok"){
            alert("打印成功");

            //

        }else{
            alert("打印失敗:"+obj.data);
        }
        //console.log(data);

    }
});

});
//打印客戶基本信息 end

//打印支票 begin
$("#btn_cheque").click(function(){
var ip = $("#ip").val();
var port = $("#port").val();

if(ip==""||port==""){alert("ip,port不能為空"); return false;}

$.post("http://"+ip+":"+port+"/printreport",
{
  "ReportName": encodeURIComponent("bankcheque.grf"),     /*報(bào)表文件名 支票套打 */
  "ReportVersion": 1,              /*可選。報(bào)表版本, 為空則默認(rèn)1  如果本地報(bào)表的版本過(guò)低 將從 ReportUrl 地址進(jìn)行下載更新*/
  "ReportUrl": encodeURIComponent("http://111.67.202.157:9099/report/bankcheque.grf"),                  /*可選。為空 將不更新本地報(bào)表 , 如果本地報(bào)表不存在可以從該地址自動(dòng)下載*/
  "Copies": 1,                  /*可選。打印份數(shù),支持指定打印份數(shù)。默認(rèn)1份,如果為零,不打印,只返回報(bào)表生成的pdf,jpg等文件*/
  "PrinterName": encodeURIComponent($("#PrinterS option:selected").text()),      /*可選。指定打印機(jī),為空的話 使用默認(rèn)打印機(jī), 請(qǐng)?jiān)?控制面板 -> 設(shè)備和打印機(jī) 中查看您的打印機(jī)的名稱 */
  "PrintOffsetX": 0,                 /*可選。打印右偏移,單位厘米。報(bào)表的水平方向上的偏移量,向右為正,向左為負(fù)。*/
  "PrintOffsetY": 0,                /*可選。打印下偏移,單位厘米。 報(bào)表的垂直方向上的偏移量,向下為正,向上為負(fù)。*/
  "token": encodeURIComponent("aa"),      /*可選。只要token值在列表中 方可打印*/

  "Parameter": encodeURIComponent('['  ///*參數(shù),type 默認(rèn)為空即可,已經(jīng)在報(bào)表端設(shè)置了 備用字段  
    +'{"type": "", "name": "PayTo","value": "山東易橋智能科技有限公司","required": false},'  //收款人
    +'{"type": "", "name": "Year","value": "2019","required": false},'//年
    +'{"type": "", "name": "Month","value": "8","required": false},'//月
    +'{"type": "", "name": "Day","value": "19:20191101000001","required": false},'//日
    +'{"type": "", "name": "Amount","value": "50000","required": false},'//金額
    +'{"type": "", "name": "Usage","value": "HttpPrinter技術(shù)服務(wù)費(fèi)","required": false},'//用途
    +'{"type": "", "name": "Remark","value": "費(fèi)用繳納一次,永久技術(shù)支持","required": false},'//備注
    +']'),          

},
function(data){
    data = decodeURIComponent(data);
    //alert(data);

    if(data==""){
        alert("連接HttpPrinter失敗");
    }else{
        //alert(data);
        var obj = JSON.parse(data);
        //alert(obj.status);

        if(obj.status=="ok"){
            alert("打印成功");

            //

        }else{
            alert("打印失敗:"+obj.data);
        }
        //console.log(data);

    }
});

});
//打印支票 end

//打印快遞單 begin
$("#btn_ExpressBill").click(function(){
var ip = $("#ip").val();
var port = $("#port").val();

if(ip==""||port==""){alert("ip,port不能為空"); return false;}

$.post("http://"+ip+":"+port+"/printreport",
{
  "ReportName": encodeURIComponent("ExpressBill.grf"),     /*報(bào)表文件名 快遞單套打 */
  "ReportVersion": 1,              /*可選。報(bào)表版本, 為空則默認(rèn)1  如果本地報(bào)表的版本過(guò)低 將從 ReportUrl 地址進(jìn)行下載更新*/
  "ReportUrl": encodeURIComponent("http://111.67.202.157:9099/report/ExpressBill.grf"),                  /*可選。為空 將不更新本地報(bào)表 , 如果本地報(bào)表不存在可以從該地址自動(dòng)下載*/
  "Copies": 1,                  /*可選。打印份數(shù),支持指定打印份數(shù)。默認(rèn)1份,如果為零,不打印,只返回報(bào)表生成的pdf,jpg等文件*/
  "PrinterName": encodeURIComponent($("#PrinterS option:selected").text()),      /*可選。指定打印機(jī),為空的話 使用默認(rèn)打印機(jī), 請(qǐng)?jiān)?控制面板 -> 設(shè)備和打印機(jī) 中查看您的打印機(jī)的名稱 */
  "PrintOffsetX": 0,                 /*可選。打印右偏移,單位厘米。報(bào)表的水平方向上的偏移量,向右為正,向左為負(fù)。*/
  "PrintOffsetY": 0,                /*可選。打印下偏移,單位厘米。 報(bào)表的垂直方向上的偏移量,向下為正,向上為負(fù)。*/
  "token": encodeURIComponent("aa"),      /*可選。只要token值在列表中 方可打印*/

  "Parameter": encodeURIComponent('['  ///*參數(shù),type 默認(rèn)為空即可,已經(jīng)在報(bào)表端設(shè)置了 備用字段  
    +'{"type": "", "name": "EmployeeID","value": "","required": false},'  
    +'{"type": "", "name": "LastName","value": "高","required": false},'  
    +'{"type": "", "name": "FirstName","value": "文杰","required": false},'  
    +'{"type": "", "name": "Title","value": "新浪中國(guó)有限公司","required": false},'  
    +'{"type": "", "name": "Region","value": "北京","required": false},'  
    +'{"type": "", "name": "City","value": "北京","required": false},'  
    +'{"type": "", "name": "Country","value": "海淀","required": false},'  
    +'{"type": "", "name": "Address","value": "學(xué)院路100號(hào)","required": false},'  
    +'{"type": "", "name": "PostalCode","value": "100100","required": false},'  
    +']'),          

},
function(data){
    data = decodeURIComponent(data);
    //alert(data);

    if(data==""){
        alert("連接HttpPrinter失敗");
    }else{
        //alert(data);
        var obj = JSON.parse(data);
        //alert(obj.status);

        if(obj.status=="ok"){
            alert("打印成功");

            //

        }else{
            alert("打印失敗:"+obj.data);
        }
        //console.log(data);

    }
});

});
//打印快遞單 end

//打印員工檔案 begin
$("#btn_employee").click(function(){
var ip = $("#ip").val();
var port = $("#port").val();

if(ip==""||port==""){alert("ip,port不能為空"); return false;}
var aBase64String = "/9j/4AAQSkZJRgABAQEACiiigAooooA/9k=";

$.post("http://"+ip+":"+port+"/printreport",
{
  "ReportName": encodeURIComponent("employee.grf"),     /*報(bào)表文件名 員工檔案 */
  "ReportVersion": 1,              /*可選。報(bào)表版本, 為空則默認(rèn)1  如果本地報(bào)表的版本過(guò)低 將從 ReportUrl 地址進(jìn)行下載更新*/
  "ReportUrl": encodeURIComponent("http://111.67.202.157:9099/report/employee.grf"),                  /*可選。為空 將不更新本地報(bào)表 , 如果本地報(bào)表不存在可以從該地址自動(dòng)下載*/
  "Copies": 1,                  /*可選。打印份數(shù),支持指定打印份數(shù)。默認(rèn)1份,如果為零,不打印,只返回報(bào)表生成的pdf,jpg等文件*/
  "PrinterName": encodeURIComponent($("#PrinterS option:selected").text()),      /*可選。指定打印機(jī),為空的話 使用默認(rèn)打印機(jī), 請(qǐng)?jiān)?控制面板 -> 設(shè)備和打印機(jī) 中查看您的打印機(jī)的名稱 */
  "PrintOffsetX": 0,                 /*可選。打印右偏移,單位厘米。報(bào)表的水平方向上的偏移量,向右為正,向左為負(fù)。*/
  "PrintOffsetY": 0,                /*可選。打印下偏移,單位厘米。 報(bào)表的垂直方向上的偏移量,向下為正,向上為負(fù)。*/
  "token": encodeURIComponent("aa"),      /*可選。只要token值在列表中 方可打印*/

  "Field": encodeURIComponent('['  ///*字段, type ftBlob (base64格式) ,ftString ftInteger ftBoolean, ftFloat, ftCurrency,ftDateTime,  size (ftString 設(shè)置為實(shí)際長(zhǎng)度,其他的設(shè)置為0,例如 ftInteger ftBlob 等設(shè)置為0 ) 
    +'{"type": "ftString", "name": "Name","size": 255,"required": false},'//姓名
    +'{"type": "ftString", "name": "tel","size": 255,"required": false},'//電話
    +'{"type": "ftDateTime", "name": "BirthDate","size": 0,"required": false},'//出生日期
    +'{"type": "ftString", "name": "Address","size": 255,"required": false},'
    +'{"type": "ftBlob", "name": "photo2","size": 0,"required": false},'
    +']'),

  "Data": encodeURIComponent('['  ///*數(shù)據(jù)行  
    +'{"Name": "高文杰", "tel": "13165191728", "BirthDate": "1988-12-01", "Address": "東滿大街12號(hào)", '
    +'"photo2": "/9j/4AAQSkZJRgABAQEACiiigAooooA/9k="}, '

    +'{"Name": "張三", "tel": "13165191728", "BirthDate": "1988-12-01", "Address": "北京市西門大街22號(hào)", '
    +'"photo2": "/9j/4AAQSkZJRgABAQEACiiigAooooA/9k="}, '

    +']'),

},
function(data){
    data = decodeURIComponent(data);
    //alert(data);

    if(data==""){
        alert("連接HttpPrinter失敗");
    }else{
        //alert(data);
        var obj = JSON.parse(data);
        //alert(obj.status);

        if(obj.status=="ok"){
            alert("打印成功");

            //

        }else{
            alert("打印失敗:"+obj.data);
        }
        //console.log(data);

    }
});

});
//打印員工檔案 end

});
</script>
</head>
<body>

IP: <input type="text" name="ip" id="ip" value="127.0.0.1" /><br>
port: <input type="text" name="port" id="port" value="12345"/><br>

<select name="PrinterS" id="PrinterS"></select>
<button id="btn_getprintlist">獲取打印機(jī)列表</button><br>

<button id="btn_printtest">打印測(cè)試報(bào)表</button><br>

<button id="btn_barcode">打印條形碼</button><br>

<button id="btn_pos">Pos小票打印</button><br>

<button id="btn_customer">打印客戶基本信息</button><br>

<button id="btn_cheque">打印支票</button><br>

<button id="btn_ExpressBill">打印快遞單</button><br>

<button id="btn_employee">打印員工檔案</button><br>

</body>
</html>

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI