W
wzpwb
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TMainFrame.btn_printClick(Sender: TObject);
var
Device: array[0..255] of Char;
Driver: array[0..255] of Char;
Port: array[0..255] of Char;
hDMode: THandle;
pDMode: PDevMode;
ScaleX, ScaleY, k, n: Integer;
begin
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then
begin
pDMode := GLobalLock(hDMode);
if pDMode <> nil then
begin
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperLength := 992;
?
pDMode^.dmPaperWidth := 2070;
pDMode^.dmFields := pDMode^.dmFields or DM_PAPERSIZE or DM_PAPERLENGTH or
DM_PAPERWIDTH;
ResetDC(Printer.Handle, pDMode^);
GLobalUnLock(hDMode);
end;
end;
n := strtoint(Edit_StartNum.Text);
Printer.begin
Doc;
try
while (n <= StrToInt(Edit_EndNum.Text)) and btn_Stop.Enableddo
begin
ScaleX := GetDeviceCaps(Printer.Canvas.Handle, logPixelsX) div
PixelsPerInch;
ScaleY := GetDeviceCaps(Printer.Canvas.Handle, logPixelsY) div
PixelsPerInch;
PrintMark(Printer.Canvas, ScaleX, ScaleY, n);//打印过程
n := n + 1;
if n <= StrToInt(Edit_EndNum.Text) then
Printer.NewPage;
sleep(500);
Application.ProcessMessages;
end
finally
Printer.EndDoc;
end;
end;
procedure TMainFrame.PrintMark(C: TCanvas;
ScaleX, ScaleY, n: Integer);
var
P, CustName, CustOrd, ShipPlace, Num, Ord: TPoint;
pc:string;
AcWidth: integer;
function ScalePoint(X, Y: Integer): TPoint;
begin
Result := Point(X * ScaleX, Y * ScaleY);
end;
begin
pc:=trim(edit1.text);
AcWidth := 770;
CustName.X := 165;
CustName.Y := 85;
CustOrd.X := CustName.X - 140;
CustOrd.Y := CustName.Y + 85;
ShipPlace.X := CustName.X - 50;
ShipPlace.Y := CustOrd.Y + 53;
Num.X := CustName.X + 60;
Num.Y := ShipPlace.Y + 75;
Ord.X := CustName.X + 50;
Ord.Y := Num.Y + 115;
with Cdo
begin
Font.Name := 'SimSun';
Font.Size := 20;
P := ScalePoint(CustName.X, CustName.Y);
TextOut(P.X, P.Y, Trim(Edit_CustName.Text));
P := ScalePoint(CustName.X + AcWidth, CustName.Y);
TextOut(P.X, P.Y, Trim(Edit_CustName.Text));
P := ScalePoint(CustOrd.X, CustOrd.Y);
TextOut(P.X, P.Y, Trim(Edit_CustOrd.Text));
P := ScalePoint(CustOrd.X + AcWidth, CustOrd.Y);
TextOut(P.X, P.Y, Trim(Edit_CustOrd.Text));
P := ScalePoint(ShipPlace.X, ShipPlace.Y);
TextOut(P.X, P.Y, Trim(Edit_ShipPlace.Text));
P := ScalePoint(ShipPlace.X + AcWidth, ShipPlace.Y);
TextOut(P.X, P.Y, Trim(Edit_ShipPlace.Text));
P := ScalePoint(Num.X, Num.Y);
TextOut(P.X, P.Y, Trim(inttostr +pc+ ' ()'));
P := ScalePoint(Num.X + AcWidth, Num.Y);
TextOut(P.X, P.Y, Trim(inttostr + pc+' ()'));
P := ScalePoint(Ord.X, Ord.Y);
TextOut(P.X, P.Y, Trim(Edit_Ord.Text));
P := ScalePoint(Ord.X + AcWidth, Ord.Y);
TextOut(P.X, P.Y, Trim(Edit_Ord.Text));
end;
end;
打印基本上就是这样,程序调试没有问题,打印也能打,问题是如果打印两张或以上纸张间距就会有误差[是向下偏],但缩小纸张高度小于992又会跳两张多纸[是属于标签纸类型],大于则误差越大,请各位大虾帮忙分析,我的纸张格式是[width:=240mm,length=89mm]。我也把该段程序改成用QUICKREPORT做的报表,但设置打印机纸张如果length小于100mm好像就不打了,大于该值就可以打。我怀疑是不是由于纸张的高度太小了。但是这也不是特别小啊,总比车票什么的大吧。为什么那些能打呢?
请各位给出出主意吧!
var
Device: array[0..255] of Char;
Driver: array[0..255] of Char;
Port: array[0..255] of Char;
hDMode: THandle;
pDMode: PDevMode;
ScaleX, ScaleY, k, n: Integer;
begin
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then
begin
pDMode := GLobalLock(hDMode);
if pDMode <> nil then
begin
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperLength := 992;
?
pDMode^.dmPaperWidth := 2070;
pDMode^.dmFields := pDMode^.dmFields or DM_PAPERSIZE or DM_PAPERLENGTH or
DM_PAPERWIDTH;
ResetDC(Printer.Handle, pDMode^);
GLobalUnLock(hDMode);
end;
end;
n := strtoint(Edit_StartNum.Text);
Printer.begin
Doc;
try
while (n <= StrToInt(Edit_EndNum.Text)) and btn_Stop.Enableddo
begin
ScaleX := GetDeviceCaps(Printer.Canvas.Handle, logPixelsX) div
PixelsPerInch;
ScaleY := GetDeviceCaps(Printer.Canvas.Handle, logPixelsY) div
PixelsPerInch;
PrintMark(Printer.Canvas, ScaleX, ScaleY, n);//打印过程
n := n + 1;
if n <= StrToInt(Edit_EndNum.Text) then
Printer.NewPage;
sleep(500);
Application.ProcessMessages;
end
finally
Printer.EndDoc;
end;
end;
procedure TMainFrame.PrintMark(C: TCanvas;
ScaleX, ScaleY, n: Integer);
var
P, CustName, CustOrd, ShipPlace, Num, Ord: TPoint;
pc:string;
AcWidth: integer;
function ScalePoint(X, Y: Integer): TPoint;
begin
Result := Point(X * ScaleX, Y * ScaleY);
end;
begin
pc:=trim(edit1.text);
AcWidth := 770;
CustName.X := 165;
CustName.Y := 85;
CustOrd.X := CustName.X - 140;
CustOrd.Y := CustName.Y + 85;
ShipPlace.X := CustName.X - 50;
ShipPlace.Y := CustOrd.Y + 53;
Num.X := CustName.X + 60;
Num.Y := ShipPlace.Y + 75;
Ord.X := CustName.X + 50;
Ord.Y := Num.Y + 115;
with Cdo
begin
Font.Name := 'SimSun';
Font.Size := 20;
P := ScalePoint(CustName.X, CustName.Y);
TextOut(P.X, P.Y, Trim(Edit_CustName.Text));
P := ScalePoint(CustName.X + AcWidth, CustName.Y);
TextOut(P.X, P.Y, Trim(Edit_CustName.Text));
P := ScalePoint(CustOrd.X, CustOrd.Y);
TextOut(P.X, P.Y, Trim(Edit_CustOrd.Text));
P := ScalePoint(CustOrd.X + AcWidth, CustOrd.Y);
TextOut(P.X, P.Y, Trim(Edit_CustOrd.Text));
P := ScalePoint(ShipPlace.X, ShipPlace.Y);
TextOut(P.X, P.Y, Trim(Edit_ShipPlace.Text));
P := ScalePoint(ShipPlace.X + AcWidth, ShipPlace.Y);
TextOut(P.X, P.Y, Trim(Edit_ShipPlace.Text));
P := ScalePoint(Num.X, Num.Y);
TextOut(P.X, P.Y, Trim(inttostr +pc+ ' ()'));
P := ScalePoint(Num.X + AcWidth, Num.Y);
TextOut(P.X, P.Y, Trim(inttostr + pc+' ()'));
P := ScalePoint(Ord.X, Ord.Y);
TextOut(P.X, P.Y, Trim(Edit_Ord.Text));
P := ScalePoint(Ord.X + AcWidth, Ord.Y);
TextOut(P.X, P.Y, Trim(Edit_Ord.Text));
end;
end;
打印基本上就是这样,程序调试没有问题,打印也能打,问题是如果打印两张或以上纸张间距就会有误差[是向下偏],但缩小纸张高度小于992又会跳两张多纸[是属于标签纸类型],大于则误差越大,请各位大虾帮忙分析,我的纸张格式是[width:=240mm,length=89mm]。我也把该段程序改成用QUICKREPORT做的报表,但设置打印机纸张如果length小于100mm好像就不打了,大于该值就可以打。我怀疑是不是由于纸张的高度太小了。但是这也不是特别小啊,总比车票什么的大吧。为什么那些能打呢?
请各位给出出主意吧!