问题:
var i, j: Integer; top, left: Integer; //x, y: Integer; PageHeight, linespace: Integer; PDMode:PDevMode; begin top:= 150; //Top 起始行的位置,比如设置 Top := 20; left:= 20; //Left 左边的起始位置,比如设置:Left := 20; PageHeight := 2600;//A4得纸张大概是这么多,我既不太清,你可以通过某个过程先得到这个数据, y:= top; x:= left; linespace:= 20; //行间距 try Printer.GetPrinter(Device, Driver, Port, AdevMode); Edit2.Text:= Device; Edit3.Text:= Driver; Edit7.Text:= Port; if AdevMode <> 0 then begin PDMode:= GlobalLock(AdevMode); if PDMode <> nil then begin case pDMode.dmPaperSize of DMPAPER_USER: showmessage('纸张类型:自定义'); DMPAPER_A3: showmessage('纸张类型:A3'); DMPAPER_A4: showmessage('纸张类型:A4'); DMPAPER_A5: showmessage('纸张类型:A5'); DMPAPER_B4: showmessage('纸张类型:B4'); DMPAPER_B5: showmessage('纸张类型:B5'); else showmessage('纸张类型:其它'); end; GlobalUnLock(AdevMode); Printer.PrinterIndex:= Printer.PrinterIndex; end; end; Printer.BeginDoc; Printer.Canvas.Font.Size:= 15; Printer.Canvas.Font.Style:= [fsBold]; //字体粗体 {Printer.Canvas.TextOut(x, 10, PrinterText[1]); Printer.Canvas.TextOut(x, 30, PrinterText[2]); Printer.Canvas.TextOut(x, 50, PrinterText[3]); Printer.Canvas.TextOut(x, 70, PrinterText[4]); Printer.Canvas.TextOut(x, 90, PrinterText[5]); Printer.Canvas.TextOut(x, 110, PrinterText[6]); Printer.Canvas.TextOut(x, 130, PrinterText[7]); Printer.Canvas.TextOut(x, 150, PrinterText[8]); Printer.Canvas.TextOut(x, 170, PrinterText[9]); } for i := 1 to 9 do begin Printer.Canvas.TextOut(x, y, PrinterText[i]); y := y + LineSpace; if(y > PageHeight - Top) then begin Printer.NewPage; y := Top; end; end; //Printer.Canvas.TextOut(StrToInt(Edit8.Text), StrToInt(Edit10.Text), print_text); Printer.EndDoc; for j:= 1 to 9 do PrinterText[j]:= ''; y:= top; x:= left; except ShowMessage('没有发现打印机的存在, 请检查是否有安装打印机'); end;
为什么打印的时候都挤在一起. 而且只有一行显示.(x,y 是全局变量), 为什么没有按我的一行加上间距一行的打印呢?
复:
打印机分辨率不一样,不要给定具体值,必须通过API获得具体打印参数。
linespace:=Printer.Canvas.TextHeight('行高');// 获得当前打印机行高度,可能远远大于20。
你先更改这两个地方再打印试试。
Printer.Canvas.TextOut(x, 10, PrinterText[1]); Printer.Canvas.TextOut(x, 30, PrinterText[2]); Printer.Canvas.TextOut(x, 50, PrinterText[3]); Printer.Canvas.TextOut(x, 70, PrinterText[4]); Printer.Canvas.TextOut(x, 90, PrinterText[5]); Printer.Canvas.TextOut(x, 110, PrinterText[6]); Printer.Canvas.TextOut(x, 130, PrinterText[7]); Printer.Canvas.TextOut(x, 150, PrinterText[8]); Printer.Canvas.TextOut(x, 170, PrinterText[9]);
你这是要干嘛,如果喷墨激光打印机,肯定打在一起了,若你要分行打,可以改成
n:=1 to 9
要打成一列,改成类似这样
Printer.Canvas.TextOut(x, y+linespacen*(n-1), PrinterText[n]);
要打成一行,改成类似这样
Printer.Canvas.TextOut(x+(n-1)*20,y, PrinterText[n]);