票据套打时,怎么控制纸张大小,和退纸(200分)

  • 主题发起人 主题发起人 wangquan
  • 开始时间 开始时间
W

wangquan

Unregistered / Unconfirmed
GUEST, unregistred user!
因为第一页打印完了
由于纸是连续的
第二页的打印位置已经过了
所以要退一点
我用的是EPSON打印机LQ_300K+
 
文本打印,使用打印机控制码,可做到精确打印连续纸.
 
打印机控制码
怎么写代码的
来控制定位和退纸及设置纸长
 
这些票据打印机手册上都会有的,
这是票据打印一段代码(Epson LQ300K),仅供参考:
procedure PrintTicket(AStation,Achannel,Auserid,ATicketNo,
AMoney,APntdate,APnttime:string);stdcall;
var
F:TextFile;
...
begin
....
Assignfile(f,'LPT1');

rewrite(f);
{初始化打印机}
Write(f,chr(27)+'@');
//Chr(27)+'@' 即ESC @ 指令
{设置汉字显示方式}
write(f,chr(28)+chr(ord('&')));
//Chr(28) 即 FS
{设定打印相对水平位置}
Write(f,chr(27)+chr(ord('/'))+chr($CF)+chr($00));
//设置高速打印
//write(f,chr(28)+chr(ord('x'))+chr($01));
Writeln(f,PrintChannel+space(16)+Auserid+space(12)+carType);
Writeln(f);
write(f,chr(27)+chr(ord('/'))+chr($CF)+chr($00));
Write(f, AMoney);
Writeln(f,Space(26)+PrntTicketno);
Writeln(f);
write(f,chr(27)+chr(ord('/'))+chr($CF)+chr($00));
//Writeln(f);
Writeln(f,Apntdate+Space(12)+ApntTime);
//顺时针走纸控制
Writeln(f,chr(27)+chr(ord('J'))+chr($FF));
Writeln(f,chr(27)+chr(ord('J'))+chr($20));
flush(f);
Closefile(f);
end;
 
Escape试试
我用自定义纸张大小打发票,还是比较准确,但要做到精确还是有点难度的.
 
不同的打印机控制码会有所不同,具体参考打印机手册。
 
打印前调用以下函数
procedure SetPaperSize(X, Y: Integer);
// 这段代码绝对可用。单位是0.1mm
// A4时 Printer.Pagewidth:=1440; A5时 Printer.Pagewidth:=1049;
// B5时 Printer.Pagewidth:=1290; 16K时 Printer.Pagewidth:=1035;
// lq1600宽行打印机这个值宽度最大为42cm左右, 长度大约2m。
{Question:
How can I change the papersize of my print job?
Answer:
One way to change printer settings at the start
of a print job is to change the printer's devicemode
structure.
See: TDEVMODE in the Delphi 1.02 help file or DEVMODE
in the Delphi 2.01 help file for other settings you can
change (providing the print driver supports the change).
The following example, contains code to change the papersize and
the paper bin that is uses:}
var
Device: array[0..255] of char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
hDMode: THandle;
PDMode: PDEVMODE;
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then
begin
if (x = 0) or (y = 0) then
begin
{Set to legal}
pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
{pDMode^.dmPaperSize := DMPAPER_LEGAL;
changed by wulianmin}
pDMode^.dmPaperSize := DMPAPER_FANFOLD_US;
end
else
begin
{Set to custom size}
pDMode^.dmFields := pDMode^.dmFields or
DM_PAPERSIZE or
DM_PAPERWIDTH or
DM_PAPERLENGTH;
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperWidth := x {SomeValueInTenthsOfAMillimeter};
pDMode^.dmPaperLength := y {SomeValueInTenthsOfAMillimeter};
end;
{Set the bin to use}
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;
GlobalUnlock(hDMode);
end;
end;
Printer.PrinterIndex := Printer.PrinterIndex;
//以下开始打印
end;


 
unit PrinterStatus;
interface
uses
Windows, Messages, WinProcs, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs;
type
TPrinterStatus = class(TComponent)
private
fStatus : Byte;
fLPT : Integer;
Function GetTimeOut : Boolean;
Function GetIOError : Boolean;
Function GetPrinterSelected : Boolean;
Function GetOutOfPaper : Boolean;
Function GetAcknowledgement : Boolean;
Function GetPrinterBusy : Boolean;
public
Procedure CheckPrinterStatus;
Constructor Create(AOwner : TComponent);
Override;
Property TimeOut : Boolean Read GetTimeOut;
Property IOError : Boolean Read GetIOError;
Property PrinterSelected : Boolean Read GetPrinterSelected;
Property OutOfPaper : Boolean Read GetOutOfPaper;
Property Acknowledgement : Boolean Read GetAcknowledgement;
Property Busy : Boolean Read GetPrinterBusy;

end;

implementation
Function TPrinterStatus.GetTimeOut : Boolean;
begin

Result:=(fStatus and $01)=$01;
end;

Function TPrinterStatus.GetIOError : Boolean;
begin

Result:=(fStatus and $08)=$08;
end;

Function TPrinterStatus.GetPrinterSelected : Boolean;
begin

Result:=(fStatus and $10)=$10;
end;

Function TPrinterStatus.GetOutOfPaper : Boolean;
begin

Result:=(fStatus and $20)=$20;
end;

Function TPrinterStatus.GetAcknowledgement : Boolean;
begin

Result:=(fStatus and $40)=$40;
end;

Function TPrinterStatus.GetPrinterBusy : Boolean;
begin

Result:=not ((fStatus and $80)=$80);
end;

Procedure TPrinterStatus.CheckPrinterStatus;
Var
Status : Byte;
CheckLPT : Word;
begin
Status:=0;
If (fLPT>=1) and (fLPT<=3) then
begin
CheckLPT:=fLPT-1;
asm
mov dx,CheckLPT;
mov al,0;
mov ah,2;
int 17h;
mov &amp;Status, ah;
end;
end;
fStatus:=Status;
end;

Constructor TPrinterStatus.Create(AOwner : TComponent);
begin

Inherited Create(AOwner);
fLPT:=1;
fStatus:=0;
end;

end.

 
你在下面加一些空格就OK拉
 
关注,对ZRWeng所说的控制码感兴趣,有没有更多的实例?
 
ZRWeng :
能用例子说明怎么让打印机在打印前后退2行,设定纸张的大小
是怎么控制的
我的打印机是LQ_300K+
你的方法进纸没问题
 
》怎么让打印机在打印前后退2行,设定纸张的大小
将打印机纸张类型设为自定义,自定义纸张大小,
这类代码很多,搜索一下,以上也有给出了一些
至于,打印前后退2行,先将纸张在打印机装好,控制好
其装纸位置(可微调打印机),打印后重要的是走纸的控制,
最好是用控制码控制,实在没办法的话,你也可以用
writeln(f)
writeln(f)
这样的折行控制。
 
ZRWeng,你的答案很好,请问一下:
//顺时针走纸控制
Writeln(f,chr(27)+chr(ord('J'))+chr($FF));
Writeln(f,chr(27)+chr(ord('J'))+chr($20));
是表示进多少,如果我要精确进纸,应该怎样输入参数值
 
>>//顺时针走纸控制
>>Writeln(f,chr(27)+chr(ord('J'))+chr($FF));
>>Writeln(f,chr(27)+chr(ord('J'))+chr($20));
这个是我根据打印机控制码指令
执行n/180英寸顺方向走纸 Esc J n (1<=n<=255)
以及打印票据纸张的高度,来调整打印连续纸时的走纸长度。
另外,这里还有一些LQ300K的一些打印位置控制码指令:
设定高速打印 FS x n (n=0,1)
设定绝对水平打印位置 Esc ¥ nL nH (0<=nH<=127
0<=nL<=255)
设定相对水平打印位置 Esc / nL nH (同上)
供参考。具体你可以查看你的打印机手册。
 
ZRWeng
谢谢你指教
 

Similar threads

I
回复
0
查看
811
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
610
import
I
后退
顶部