由于网页打印不行,要么sdk 写成activex,这样浏览器支持又有局限。
因此,采用客户端编写打印服务启动,定时轮询服务端打印队列,从服务的获取打印队列进行打印。
服务端web 点击打印,讲打印数据写到打印队列的表中。
打印服务客户端程序 调用TSCLIB.dll 进行打印。
delphi 代码:
//打印
procedure printcp(code: string; cl: string; lb: string; cd: string; gg: string; bz: string; lh: string; yzh: string);
var
i: Integer;
pStr: PChar;
begin
//openport('Gprinter GP-2120T');
openport(PChar(port));
clearbuffer;
setup('50', '40', '2', '9', '0', '2', '0');
sendcommand('DIRECTION 1');
windowsfont(strtoint(x), strtoint(y1) - 30, 25, 0, 2, 0, 'Arial', pchar('南京xx金属材料科技有限公司'));
barcode(x, y1, '39', '64', '1', '0', '1', '4', pchar(code));
windowsfont(strtoint(x), strtoint(y1) + 90, 25, 0, 2, 0, 'Arial', pchar('材料:' + cl + ' 类别:' + lb));
windowsfont(strtoint(x), strtoint(y1) + 120, 25, 0, 2, 0, 'Arial', pchar('产地:' + cd));
windowsfont(strtoint(x), strtoint(y1) + 150, 25, 0, 2, 0, 'Arial', pchar('规格:' + gg + ' 标准:' + bz));
windowsfont(strtoint(x), strtoint(y1) + 180, 25, 0, 2, 0, 'Arial', pchar('炉批号:' + lh));
windowsfont(strtoint(x), strtoint(y1) + 210, 25, 0, 2, 0, 'Arial', pchar('移植号:' + yzh));
printlabel('1', '1');
closeport;
end;
//获取数据 打印job
procedure TForm1.printjob(url: string);
var
HttpClient: TIdHttp;
ParamList: TStringList;
ResponseStr: string;
aJson,jo,jt:ISuperObject;
code, cl,lb,cd, gg, bz,lh,yzh: string;
gid:string;
i:integer;
begin
url:='/getPrintJob.shtml';
//获取远程打印队列
try
HttpClient := TIdHttp.Create(nil);
ParamList := TStringList.Create;
ParamList.Add('');
ResponseStr := HttpClient.Post(basepath + url, ParamList);
if ResponseStr ='[]' then begin
exit;
end;
//mmo1.Lines.Add(ResponseStr);
ResponseStr:=StringReplace (ResponseStr, '[', '', [rfReplaceAll]);
ResponseStr:=StringReplace (ResponseStr, ']', '', [rfReplaceAll]);
aJson:=SO(ResponseStr);
//[{"id":20,"goodscode":"GC25","material":"316/316L","typename":"绠℃潗","company":"涔呯珛","model":"89*4","standard":"GB/T14976-2012","furnacenum":"YX1710-148","batchnum":"171L11040","verno":"2100019759-3","isDel":1,"createUserId":1,"createTime":"2019-05-23 15:28:22.0"}]
gid:=ajson.S['id'];
code:=ajson.S['goodscode'];
cl:=ajson.S['material'];
lb:=ajson.S['typeName'];
cd:=ajson.S['company'];
gg:=ajson.S['model'];
bz:=ajson.S['standard'];
lh:=ajson.S['furnacenum']+'/'+ajson.S['batchnum'];
yzh:=ajson.S['verno'];
HttpClient.Free;
//判断是否在本地打印队列里
i:=lstjob.Items.IndexOf(gid);
if i>=0 then begin
// 打印
printcp(code,cl,lb,cd,gg,bz,lh,yzh);
//删除远程队列
deljob(gid);
//删除本地
lstjob.Items.Delete(i);
end else begin //如果不在打印队列
lstjob.Items.Add(gid);
i:=lstjob.Items.IndexOf(gid);
printcp(code,cl,lb,cd,gg,bz,lh,yzh);
//删除远程队列
if deljob(gid) then
lstjob.Items.Delete(i); //删除本地
end;
//
except
HttpClient.Free;
end;
end;
function deljob(id: string):boolean;
var
HttpClient: TIdHttp;
ParamList: TStringList;
ResponseStr: string;
begin
result:=true;
try
HttpClient := TIdHttp.Create(nil);
ParamList := TStringList.Create;
ParamList.Add('ids='+id);
ResponseStr := HttpClient.Post(basepath +'/printJob/DelPrintJob.shtml', ParamList);
HttpClient.Free;
except
result:=false;
HttpClient.Free;
end;
end;