Printer打印到纸张产生的页边距的问题,打印高手帮忙啊!!!
我用printer打印到A4纸,在(8,2)厘米处输出字符 国国国国国国
但是实际打出来后,用尺子量 x,y座标并不是8和2,我用
x :=GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
y :=GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);
减去这个x,y偏移也不对,也不等于8和2,请高手帮忙,如何使
Printer.Canvas.TextOut(Round(800*dpipx/254),Round(200*dpipx/254),'国国国国国国');
打印后,量的尺寸正好是(8,2)厘米呢
代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var
dpipx,dpipy:integer;
begin
SetPaperSize_A4;
Printer.Orientation := poLandscape; //poPortrait纵向 poLandscape;横向
Printer.BeginDoc;
dpipx := GetDeviceCaps(Printer.Canvas.Handle, LOGPIXELSX);
dpipy := GetDeviceCaps(Printer.Canvas.Handle, LOGPIXELSY);
Printer.Canvas.Font.Charset := GB2312_CHARSET;
Printer.Canvas.Font.Name := '宋体';
Printer.Canvas.Font.Height := Round(50 * dpipy/254);
Printer.Canvas.Font.Style := [];
Printer.Canvas.Pen.Width := 1;
Printer.Canvas.TextOut(Round(800*dpipx/254),Round(200*dpipx/254),'国国国国国国');
Printer.EndDoc;
end;
procedure TForm1.SetPaperSize_A4;
var
aDevice: array[0..CCHDEVICENAME-1] of char;
aDriver: array[0..MAX_PATH-1] of char;
aPort: array[0..31] of char;
hDevMode: THandle;
pDevMode: PDeviceMode;
begin
Printer.GetPrinter(aDevice, aDriver, aPort, hDevMode);
if hDevMode <> 0 then
begin
pDevMode := GlobalLock(hDevMode);
if pDevMode <> nil then
begin
pDevMode^.dmPaperSize := DMPAPER_A4;
pDevMode^.dmOrientation:=DMORIENT_PORTRAIT;
pDevMode^.dmFields:=pDevMode^.dmFields or DM_PAPERSIZE;
GlobalUnlock(hDevMode);
end;
end;
end;