嘿,不就是套打吗?用尺量好座标。
方法1:在报表控件对应的位置放上你的条码数据。
方法2:自己定义纸张大小。用决定座标打印(x,y)。
相关代码如下:
RateX, RateY: Integer;//定义在private 里
//初始化打印机的一些参数
function InitPrinter: Boolean;
begin
Result := Printer.Printers.Count > 0;
RateX := MulDiv(GetDeviceCaps(Printer.Handle, LOGPIXELSX), 1000,254 );//254
RateY := MulDiv(GetDeviceCaps(Printer.Handle, LOGPIXELSY),1000,254);
end;
//设置纸张大小,x为纸张,y宽为纸张高,均以0.1mm为单位
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;
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;
//转换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;
//转换点的座标系,由0.1mm单位转换成Pixel单位
procedure TransformPoint(Point: TPoint);
begin
Point.x := TransformX(Point.x);
Point.y := TransformY(Point.y);
end;
//转换区域的座标系,由0.1mm单位转换成Pixel单位
procedure TransformRect(Rect: TRect);
begin
Rect.Left := TransformX(Rect.Left);
Rect.Right := TransformX(Rect.Right);
Rect.Top := TransformY(Rect.Top);
Rect.Bottom := TransformY(Rect.Bottom);
end;
procedure Txkz.PR1Click(Sender: TObject);
begin
if not InitPrinter then
Application.MessageBox('打印机设置不正确', '错误', mb_IconError + mb_OK)
else
begin
//定义纸张为220MMX140MM
SetPaperSize(2670, 3800);
//打印文本test
Printer.Orientation:=poLandscape;//打印方向
with Printerdo
begin
begin
Doc;
with canvasdo
begin
s:=ZSLX.Text;//你要打印的数据。
Font.Name:='楷体_GB2312';
Font.Size:=16;
TextOut(TransformX(2430), TransformY(800), S);//x=243mm,y=80mm
end;
enddoc;
end;
记住要 uses printers