//设置纸张高度:单位--0.1mm procedure SetPaperHeight(H_Dot1mm: 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 //自定义纸张最小高度127mm if H_Dot1mm < 1270 then H_Dot1mm := 1270; //自定义纸张最大高度432mm if H_Dot1mm > 4320 then H_Dot1mm := 4320; 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 := H_Dot1mm; pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL; pDMode^.dmDefaultSource := DMBIN_MANUAL; GlobalUnlock(hDMode); end; end; Printer.PrinterIndex := Printer.PrinterIndex; end;
priter.pageheiht是只读属性
procedure SetPaperHeight(H_Dot1mm: 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
//自定义纸张最小高度127mm
if H_Dot1mm < 1270 then H_Dot1mm := 1270;
//自定义纸张最大高度432mm
if H_Dot1mm > 4320 then H_Dot1mm := 4320;
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 := H_Dot1mm;
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;
GlobalUnlock(hDMode);
end;
end;
Printer.PrinterIndex := Printer.PrinterIndex;
end;