拖了几星期的打印了[纸张width:240mm,length:89mm](100分)

  • 主题发起人 主题发起人 wzpwb
  • 开始时间 开始时间
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(n) +pc+ ' ()'));
P := ScalePoint(Num.X + AcWidth, Num.Y);
TextOut(P.X, P.Y, Trim(inttostr(n) + 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又会跳两张多纸[是属于标签纸类型],大于则误差越大,请各位大虾帮忙分析!!!
 
设置打印机(通过打印机面板上的按钮)
 
我设置过了,好像没有用,我用QR做报表也试过了,但用报表打印机都无法定义这小规格的纸张,这是为何?有什么好办法呢?
 
连续打印需将页面高度设成长度length:89mm即可解决
 
ScaleX := GetDeviceCaps(Printer.Canvas.Handle, logPixelsX) div PixelsPerInch;
ScaleY := GetDeviceCaps(Printer.Canvas.Handle, logPixelsY) div PixelsPerInch;
应当把ScaleX和ScaleY设成浮点数, 修改如下:
ScaleX := GetDeviceCaps(Printer.Canvas.Handle, logPixelsX) / PixelsPerInch;
ScaleY := GetDeviceCaps(Printer.Canvas.Handle, logPixelsY) / PixelsPerInch;
在用这个比例进行计算后, 比如相乘后, 把结果用Round()换成整数, 你可以这样试试。
 
xhlight:这样好象不能调整很小距离,但我打印两张误差就有1cm多,所以还没有解决该问题!
inforum:我的页面高度长度一直是length:89mm
 
我也有同样的问题,我的纸张大小为W=121MM,L=70MM,设置打印纸大小为121X70它就向上移动,若L>70就向下移动。同时,打印第一张时它的进纸较多,打印第二张以后的就较少,不知应该怎么样解决这些问题,还望高手们指点一下。
 
设置纸张大小时需要取得水平方向、纵向每英寸打印机的点数
比如页面高度是89mm,就应该这样
Trunc(89/25.38*Vdpi+0.5);(单位为像素点)
其中
Vdpi := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
祝顺利!
 
inforum:我拿你的代码试了一下,改成了
Vdpix := GetDeviceCaps(Printer.Handle,LOGPIXELSx);
scalex:=Trunc(240/25.38*Vdpix+0.5);
Vdpiy := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
scaley:=Trunc(89/25.38*Vdpiy+0.5);
但这样打印机不打了,A4纸放下去就走纸出来了,怎么回事?
 
pDMode^.dmPaperLength := 992;
//该句不对。
高度应在1270~4320(自定义纸张最小高度127mm、最大高度432mm)之间
 
inforum:请问那该怎么办呢?
其实要实现下面的格式,用什么办法都行!!!!出出主意呀!
打印width:240mm,height:89mm纸张,格式如下:
客户 客户
地址 地址
日期 日期

种类 种类
字体为20号,请问用什么办法可以实现,有哪几种方法?我用QR报表好象不行,调用printers好象也不行.请问各位大虾有什么办法实现这种功能呀?帮帮我,这我做不出来可就要失业了呀,我还在试用期呀!!!!!!!!
 
楼主,你把如下代码原封不动COPY过去试试,应该能满足要求
注意要:uses printers;
printer.begin
Doc;
with printer.Canvas do
begin
Font.Name := 'Arial';
Font.Size := 20;
TextOut(237, 237, '客户1');
TextOut(3073, 237, '客户2');
TextOut(237, 711, '地址1');
TextOut(3073, 711, '地址2');
TextOut(237, 1185, '日期1');
TextOut(3073, 1185, '日期2');
TextOut(237, 1659, '种类1');
TextOut(3073, 1659, '种类2');
end;
printer.EndDoc;
祝顺利!
 
后退
顶部