dure SetPaperHeight(Value:integer);
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDMode : THandle;
PDMode : PDEVMODE;
begin
file://自定义纸张最小高度127mm
if Value < 127 then Value := 127;
file://自定义纸张最大高度432mm
if Value > 432 then Value := 432;
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then
begin
pDMode^.dmFields := pDMode^.dmFields or DM_PAPERSIZE or
DM_PAPERLENGTH;
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperLength := Value * 10;
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;
GlobalUnlock(hDMode);
end;
end;
Printer.PrinterIndex := Printer.PrinterIndex;
end;
file://设置纸张宽度:单位--mm
Procedure SetPaperWidth(Value:integer);
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDMode : THandle;
PDMode : PDEVMODE;
begin
file://自定义纸张最小宽度76mm
if Value < 76 then Value := 76;
file://自定义纸张最大宽度216mm
if Value > 216 then Value := 216;
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then
begin
pDMode^.dmFields := pDMode^.dmFields or DM_PAPERSIZE or
DM_PAPERWIDTH;
pDMode^.dmPaperSize := DMPAPER_USER;
file://将毫米单位转换为0.1mm单位
pDMode^.dmPaperWidth := Value * 10;
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;
GlobalUnlock(hDMode);
end;
end;
Printer.PrinterIndex := Printer.PrinterIndex;
end;
file://在 (Xmm, Ymm)处按指定配置文件信息和字体输出字符串
procedure PrintText(X, Y: Extended; Txt: string; ConfigFileName: string; FontSize: Integer=12);
var
OrX, OrY: Extended;
Px, Py: Integer;
AP: TPoint;
Fn: TStrings;
FileName: string;
OffSetX, OffSetY: Integer;
begin
file://打开配置文件,读出横向和纵向偏移量
try
Fn := TStringList.Create;
FileName := ExtractFilePath(Application.ExeName) + ConfigFileName;
if FileExists(FileName) then
begin
Fn.LoadFromFile(FileName);
file://横向偏移量
OffSetX := StrToInt(Fn.Values[''X'']);
file://纵向偏移量
OffSetY := StrToInt(Fn.Values[''Y'']);
end
else
begin
file://如果没有配置文件,则生成
Fn.Values[''X''] := ''0'';
Fn.Values[''Y''] := ''0'';
Fn.SaveToFile(FileName);
end;
finally
Fn.Free;
end;
X := X + OffSetX;
Y := Y + OffSetY;
Px := Round(Round(X * HPointsPerInch * 10000/25.4) / 10000);
Py := Round(Round(Y * VPointsPerInch * 10000/25.4) / 10000);
Py := Py - GetOffSe