Chest-PrintjQuery 打印插件
使用場(chǎng)景
Chest-Print 適用于針式打印機(jī)等需要定位打印的需求,如本人使用場(chǎng)景是打印快遞單.
如何使用
插件主體是 as3 編寫的 swf 文件,擴(kuò)充部分寫了一個(gè) jQuery 小插件,所以需要引入 jQuery 包,swfobject 包。
創(chuàng)建一個(gè)空 DIV 并創(chuàng)建 jQuery 對(duì)象:
$("#printAll").printAll();
需要一個(gè) JSON 數(shù)組參數(shù),數(shù)組中的對(duì)象為多 Page 打印,一個(gè)對(duì)象代表一個(gè)Page;Page對(duì)象中,存在width,height,frontSize(拼寫錯(cuò)誤,囧),content 屬性;Page 對(duì)象中的 Content 屬性是一個(gè)打印元素對(duì)象數(shù)組,元素對(duì)象又有 left,top,name(打印無(wú)效屬性,后臺(tái)對(duì)象轉(zhuǎn)化過來(lái)的屬性),value(打印內(nèi)容),width 屬性,例子如下,這是打印一頁(yè)快遞單:
var pages = [
{
"width": "900",
"height": "600",
"frontSize": "12",
"content": [
{
"left": "343",
"top": "345",
"name": "shipName",
"value": "收貨人小凳子",
"width": "130"
},
{
"left": "126",
"top": "373",
"name": "shipAddress",
"value": "山東省 臨沂市 費(fèi)縣 世茂大道",
"width": "309"
},
{
"left": "142",
"top": "308",
"name": "shipZip",
"value": "150000",
"width": "130"
},
{
"left": "219",
"top": "434",
"name": "shipMobile",
"value": "13569696969",
"width": "179"
},
{
"left": "358",
"top": "164",
"name": "deliverUserName",
"value": "王二虎",
"width": "134"
},
{
"left": "127",
"top": "192",
"name": "deliverAddress",
"value": "遼寧省 沈陽(yáng)市市轄區(qū) 淮海路",
"width": "253"
},
{
"left": "136",
"top": "131",
"name": "deliverZip",
"value": "1456253",
"width": "161"
},
{
"left": "210",
"top": "258",
"name": "deliverMobile",
"value": "15369554687",
"width": "153"
}
]
}
]
調(diào)用打印方法,彈出打印設(shè)置,進(jìn)行打印
$("#printAll").printAll.print(pages);
注意事項(xiàng)
首先要注意flash安全沙箱問題,請(qǐng)?jiān)跍y(cè)試環(huán)境下測(cè)試(ip或域名),文件結(jié)構(gòu)會(huì)報(bào)錯(cuò).
同樣是flex問題,需要彈出打印設(shè)置系統(tǒng)設(shè)置,并不能直接打印(安全相關(guān)).
chrome瀏覽器flash插件有2個(gè),需要禁用自帶flash插件,否則打印不出內(nèi)容.
評(píng)論
圖片
表情
