西西,我的程序中刚刚也要用到这个,解决了,贴一段给你。
const INCHES_PER_MILIMETER : Real = 0.04;
type
Toffset = record
X,Y: Integer;
end;
var
PrintCard: TPrintCard;
FDeviceName : String;
FpageHeightPixel, FpageWidthPixel : Integer;
Forientation : TprinterOrientation;
FprintOffsetPixels : Toffset;
FPixelsPerMMX,FPixelsPerMMY: Real;
MMSize, FpageHeightMM : Integer;
TheReport, TheHead, HeadLine, RecordLine, Tfname,TLame : String;
Procedure TPrintCard.GetDeviceSettings;
var
retval : integer;
PixX, pixY: Integer;
begin
FdeviceName :=Printer. Printers[Printer. PrinterIndex];
FpageHeightPixel := Printer. PageHeight;
FpageWidthPixel := Printer.PageWidth;
Forientation:=Printer.Orientation;
// $IFDEF WIN32
FprintOffsetPixels.X:= GetDeviceCaps(Printer. Handle,PHYSICALOFFSETX);
FprintOffsetPixels. Y:= GetDeviceCaps(Printer.Handle,PHYSICALOFFSETY);
// $else
retval:= Escape(Printer. Handle,GETPRINTINGOFFSET,0,nil,@FPrintOffsetPixels);
// $ENDIF
PixX:= GetDeviceCaps(Printer.Handle,LOGPIXELSX);
PixY:= GetDeviceCaps (Printer.Handle,Logpixelsy);
FPixelsPerMMX:= INCHES_PER_MILIMETER*PixX;
FPixelsPerMMY:= INCHES_PER_MILIMETER * PixY;
FpageHeightMM:= Round (FpageHeightPixel/FPixelsPerMMY);
end;
function TPrintCard.PutText(mmX,mmY: Integer;
S: string;
LeftAlign:Boolean) : boolean;
var
X,Y: Integer;
Align: WORD;
begin
if LeftAlign then
align := SetTextAlign(Printer.Handle,TA_BOTTOM or TA_LEFT)
else
align:= SetTextAlign(Printer.Handle,TA_BOTTOM or TA_RIGHT);
result:= FALSE;
X :=Trunc(mmX * FPixelsPerMMX) - FprintOffsetPixels.X;
Y := Trunc(mmY * FPixelsPerMMY) - FprintOffsetPixels.Y;
if X < 0 then
exit;
if Y < 0 then
exit;
Printer.Canvas.TextOut(X,Y,S);
Result := TRUE;
end;
这样调用:
getdevicesettings;
Printer.begin
Doc;
pixelsize:=Printer.Canvas.TextHeight('Yy');
MMsize:=Round(PixelSize/FPixelsPerMMY);
puttext(40,10,'单位',True);
Printer.EndDoc;
相信会有点用的。