var LineHeight: Integer; i,j,k: integer; X,Y: integer; dCount: Integer; zSL: integer; zJE: Currency; tmphm:Integer; begin //tmphm:=strtoint(hm); Printer.BeginDoc; Lineheight:=Printer.Canvas.TextHeight('X'); with Printer do begin i:=0; while i<RCount do begin k:=0; dCount:=0; zSL:=0; zJE:=0; for j:=i to RCount-1 do begin if k=4 then Break; Y:=180+dCount*LineHeight+(dCount+1)*4; Canvas.TextOut(135,Y,DyRecord[j].SpBh); Canvas.TextOut(315,Y,DyRecord[j].SpMc); Canvas.TextOut(450,Y,DyRecord[j].SpHh); X:=560-Length(IntToStr(DyRecord[j].SpSl))*10; zSL:=zSL+DyRecord[j].SpSl; Canvas.TextOut(X,Y,Format('%d',[DyRecord[j].SpSl])); X:=660-Length(Format('%2f',[DyRecord[j].SpJg]))*10; Canvas.TextOut(X,Y,Format('%2f',[DyRecord[j].SpJg])); X:=770-Length(Format('%2f',[DyRecord[j].SpJe]))*10; zJE:=zJE+DyRecord[j].SpJe; Canvas.TextOut(X,Y,Format('%2f',[DyRecord[j].SpJe])); Inc(dCount); Inc(k); end; Canvas.TextOut(235,345,YGXM); Canvas.TextOut(455,345,XmEdit.Text); Canvas.TextOut(235,385,IntToStr(zSL)); Canvas.TextOut(455,385,Format('%2f',[zJE])); Canvas.TextOut(655,385,DateToStr(Date)); //打印顾客 NewPage; //换页 k:=0; dCount:=0; zSL:=0; zJE:=0; for j:=i to RCount-1 do begin if k=4 then Break; Y:=180+dCount*LineHeight+(dCount+1)*4; Canvas.TextOut(135,Y,DyRecord[j].SpBh); Canvas.TextOut(315,Y,DyRecord[j].SpMc); Canvas.TextOut(450,Y,DyRecord[j].SpHh); X:=560-Length(IntToStr(DyRecord[j].SpSl))*10; zSL:=zSL+DyRecord[j].SpSl; Canvas.TextOut(X,Y,Format('%d',[DyRecord[j].SpSl])); X:=660-Length(Format('%2f',[DyRecord[j].SpJg]))*10; Canvas.TextOut(X,Y,Format('%2f',[DyRecord[j].SpJg])); X:=770-Length(Format('%2f',[DyRecord[j].SpJe]))*10; zJE:=zJE+DyRecord[j].SpJe; Canvas.TextOut(X,Y,Format('%2f',[DyRecord[j].SpJe]));//打印存根 Inc(dCount); Inc(k); end; Canvas.TextOut(235,345,YGXM); Canvas.TextOut(455,345,XmEdit.Text); Canvas.TextOut(655,345,Pj+Hm); Canvas.TextOut(235,385,IntToStr(zSL)); Canvas.TextOut(455,385,Format('%2f',[zJE])); Canvas.TextOut(655,385,DateToStr(Date)); tmphm:=tmphm+1; Hm:=IntToStr(strtoint(hm)+1); for j:=1 to 4 do if Length(Hm)<4 then Hm:='0'+Hm else Break; Inc(i,4); if i<RCount then NewPage; end; end; Printer.EndDoc; Close; end;
delphi小票打印
http://download.csdn.net/down/459298/huaya1127
var
F:TextFile;
begin
Assignfile(f,'LPT1');rewrite(f);
Write(f,chr(27)+'@'); //Chr(27)+'@' 即ESC @ 指令 WRITELN(F,'TEST1 FIRST LINE');
WRITELN(F,chr(12)); // move the paper to a new pageflush(f);
Closefile(f);end; procedure TForm1.Button2Click(Sender: TObject);
var
F:TextFile;
begin
try
AssignFile(F,'LPT1');
Rewrite(F); //打印标题
Writeln(F,chr($1b) + chr($40)); //[初始化打印机
Writeln(F,Chr($1b) + Chr($72) + '1'); //设置红色打印
Writeln(F,chr($1b) + chr($61) + '1'); //居中打印
Writeln(F,chr($1c) + chr($21) + '4'); //倍宽打印
Writeln(F,'点单打印');
Writeln(F,chr($1b) + chr($61) + '0'); //取消居中打印
//Writeln(F, '点单号:' + fGroupID); //显示帐单号,房号
//Writeln(F, '房 号:' + RmName);
Writeln(F, '点单号:' + '23232'); //显示帐单号,房号
Writeln(F, '房 号:' + 'ereer');
Writeln(F,chr($1c) + chr($21) + '0');
Writeln(F,'打印时间:' + datetimetostr(Now));
Writeln(F,'----------------------------------------');
Writeln(F,' 商品名称 数量 单价 单位 合计');
Writeln(F,'----------------------------------------'); //打印尾标
Writeln(F,'----------------------------------------');
// writeln(F,' 合计:' + CurrToStr(fTotalSum) + '元');
writeln(F,' 合计:' + '25元');
//打印完毕,切纸
Writeln(F,chr($1d)+ 'V' + chr(66) + chr(0)); //切纸
finally
closefile(F);
end; end;
LineHeight: Integer;
i,j,k: integer;
X,Y: integer;
dCount: Integer;
zSL: integer;
zJE: Currency;
tmphm:Integer;
begin
//tmphm:=strtoint(hm);
Printer.BeginDoc;
Lineheight:=Printer.Canvas.TextHeight('X');
with Printer do
begin
i:=0;
while i<RCount do
begin
k:=0;
dCount:=0;
zSL:=0;
zJE:=0;
for j:=i to RCount-1 do
begin
if k=4 then
Break;
Y:=180+dCount*LineHeight+(dCount+1)*4;
Canvas.TextOut(135,Y,DyRecord[j].SpBh);
Canvas.TextOut(315,Y,DyRecord[j].SpMc);
Canvas.TextOut(450,Y,DyRecord[j].SpHh);
X:=560-Length(IntToStr(DyRecord[j].SpSl))*10;
zSL:=zSL+DyRecord[j].SpSl;
Canvas.TextOut(X,Y,Format('%d',[DyRecord[j].SpSl]));
X:=660-Length(Format('%2f',[DyRecord[j].SpJg]))*10;
Canvas.TextOut(X,Y,Format('%2f',[DyRecord[j].SpJg]));
X:=770-Length(Format('%2f',[DyRecord[j].SpJe]))*10;
zJE:=zJE+DyRecord[j].SpJe;
Canvas.TextOut(X,Y,Format('%2f',[DyRecord[j].SpJe]));
Inc(dCount);
Inc(k);
end;
Canvas.TextOut(235,345,YGXM);
Canvas.TextOut(455,345,XmEdit.Text);
Canvas.TextOut(235,385,IntToStr(zSL));
Canvas.TextOut(455,385,Format('%2f',[zJE]));
Canvas.TextOut(655,385,DateToStr(Date)); //打印顾客
NewPage; //换页
k:=0;
dCount:=0;
zSL:=0;
zJE:=0;
for j:=i to RCount-1 do
begin
if k=4 then
Break;
Y:=180+dCount*LineHeight+(dCount+1)*4;
Canvas.TextOut(135,Y,DyRecord[j].SpBh);
Canvas.TextOut(315,Y,DyRecord[j].SpMc);
Canvas.TextOut(450,Y,DyRecord[j].SpHh);
X:=560-Length(IntToStr(DyRecord[j].SpSl))*10;
zSL:=zSL+DyRecord[j].SpSl;
Canvas.TextOut(X,Y,Format('%d',[DyRecord[j].SpSl]));
X:=660-Length(Format('%2f',[DyRecord[j].SpJg]))*10;
Canvas.TextOut(X,Y,Format('%2f',[DyRecord[j].SpJg]));
X:=770-Length(Format('%2f',[DyRecord[j].SpJe]))*10;
zJE:=zJE+DyRecord[j].SpJe;
Canvas.TextOut(X,Y,Format('%2f',[DyRecord[j].SpJe]));//打印存根
Inc(dCount);
Inc(k);
end;
Canvas.TextOut(235,345,YGXM);
Canvas.TextOut(455,345,XmEdit.Text);
Canvas.TextOut(655,345,Pj+Hm);
Canvas.TextOut(235,385,IntToStr(zSL));
Canvas.TextOut(455,385,Format('%2f',[zJE]));
Canvas.TextOut(655,385,DateToStr(Date));
tmphm:=tmphm+1;
Hm:=IntToStr(strtoint(hm)+1);
for j:=1 to 4 do
if Length(Hm)<4 then
Hm:='0'+Hm
else
Break;
Inc(i,4);
if i<RCount then
NewPage;
end;
end;
Printer.EndDoc;
Close;
end;
=============================================================
在打印小票这方面,以前碰到过问题:如是整单做完打印,还是做一笔打一笔(如不要再打一笔退单).
呵呵,主要看你应用在哪里.
如卖衣服的,你完全可以整单打应. (可以用报表方式)
如超市,生意很好的话,还是一笔一笔打比较好.. (这种就要用打印画布输出)
1、我在一个image的canvas上画了表格和textout文本输出,可是怎么拷贝到printer.canvas2、如果我直接在printer.canvas上画,我怎么实现打印预览谢谢帮助的人XDJM