关于纸张大小问题。(200分)

  • 主题发起人 主题发起人 Chxn
  • 开始时间 开始时间
C

Chxn

Unregistered / Unconfirmed
GUEST, unregistred user!
打印机Epson LQ-1600KII,winnt40
procedure TfrmMain.PageSet;
var
ADevice,ADriver,APort:string;
ADeviceMode:THandle;
DevMode:PDeviceMode;
Page:TPoint;
begin

try
SetLength(ADevice,255);
SetLength(ADriver,255);
SetLength(APort,255);
if ADeviceMode=0 then

begin

Printer.PrinterIndex:=Printer.PrinterIndex;
Printer.GetPrinter(Pchar(ADevice),PChar(ADriver),Pchar(APort),ADeviceMode);
end;

if ADeviceMode<>0 then

begin

DevMode:=GlobalLock(ADeviceMode);
try
DevMode^.dmFields:=DevMode^.dmFields or DM_PaperSize;
DevMode^.dmPaperSize:=0;//好象只有这条是关键,但是0是什么纸张类型?
DevMode^.dmFields:=DevMode^.dmFields or DM_PaperWidth;
DevMode^.dmPaperWidth:=2090;
DevMode^.dmFields:=DevMode^.dmFields or DM_PaperLength;
DevMode^.dmPaperLength:=760;//设置纸张大小20.9*7.7(cm)
finally
GlobalUnlock(ADeviceMode);
end;

end;

finally
end;

end;

实际纸张大小1032*1536 pixels 5.73*8.5(cm)
 
"0"会不会是打印机设置中的默认纸张类型。
 
1/先获取打印机的每英寸分辨率 (x,y方向)
PixelsInInchx := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
PixelsInInchy := GetDeviceCaps(Printer.Handle, LOGPIXELSy);

2/再计算所需的点数
PixelsInInchx * cm / 2.54
PixelsInInchy * cm / 2.54

3/
DevMode^.dmPaperWidth:= ...;
DevMode^.dmPaperLength:= ...

 
//转换x方向值,由0.1mm单位转换成Pixel单位
function TransformX(X: Integer): Integer;
begin

Result := MulDiv(X, RateX, 1000);
end;

//转换y方向值,由0.1mm单位转换成Pixel单位
function TransformY(Y: Integer): Integer;
begin

Result := MulDiv(Y, RateY, 1000);
end;

function InitPrinter: Boolean;
begin

Result := Printer.Printers.Count > 0;
RateX := MulDiv(GetDeviceCaps(Printer.Handle, LOGPIXELSX), 1000, 254);
RateY := MulDiv(GetDeviceCaps(Printer.Handle, LOGPIXELSY), 1000, 254);
end;

//纸张设置
procedure SetPaperSize(X, Y: Integer);
var
Device, Driver, Port: PChar;
HDMode: THandle;
PDMode: PDevMode;
begin

Device := StrAlloc(cchDeviceName);
Driver := StrAlloc(MAX_PATH);
Port := StrAlloc(32);
try
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, HDMode);
if HDMode<>0 then
begin

PDMode := GlobalLock(HDMode);
if PDMode <>nil then
begin

with PDMode^do
begin

dmPaperSize := 256 //我的打印机是256 打印机不同也可能是0
;//好象只有这条是关键,但是0是什么纸张类型?0 OR 256 是自定义纸张大小
dmPaperWidth := X;
dmPaperLength :=Y;
dmFields := dmFields or DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;
GlobalUnlock(HDMode);
end;

Printer.PrinterIndex := Printer.PrinterIndex;
end;

end;

finally
StrDispose(Device);
StrDispose(Driver);
StrDispose(Port);
end;

end;

 
我的打印机是LQ-1800K LQ1600K
 
很感谢arm,但是一切如旧。
 
多人接受答案了。
 
后退
顶部