自己定义纸张的大小。
procedure Tdm1.UpdatePrint(Awidth, Aheight: integer;
isrect: boolean);
function Win95SetForm(PDevMode: PDeviceMode): Boolean;
begin
Printer.PrinterIndex := Printer.PrinterIndex;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERSIZE;
PDevMode.dmPaperSize := 256;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERWIDTH;
PDevMode.dmPaperWidth := AWidth;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERLENGTH;
PDevMode.dmPaperLength := AHeight;
PDevMode.dmFields := PDevMode.dmFields or DMBIN_MANUAL;
// PDevMode.dmDefaultSource := DMBIN_MANUAL;
Printer.PrinterIndex := Printer.PrinterIndex;
Result := True;
end;
function WinNTSetForm(PDevMode: PDeviceMode;
Device: PChar;
Port: PChar): Boolean;
var
hPrinter: THandle;
pForm: Pointer;
cbNeeded: DWORD;
cReturned: DWORD;
FormInfo1: TFormInfo1;
begin
Result := False;
if OpenPrinter(Device, hPrinter, nil) then
begin
pForm := nil;
EnumForms(hPrinter, 1, pForm, 0, cbNeeded, cReturned);
GetMem(pForm, cbNeeded);
//取pForm的大小并分配内存
try
if EnumForms(hPrinter, 1, pForm, cbNeeded, cbNeeded, cReturned) then
begin
if DeleteForm(hPrinter, PChar(CustomFormName)) then
Dec(cReturned);
//删除旧的Form
with FormInfo1do
begin
Flags := 0;
pName := PChar(CustomFormName);
Size.cx := AWidth * 100;
Size.cy := AHeight * 100;
with ImageAbleAreado
begin
Left := 0;
Top := 0;
Right := Size.cx;
Bottom := Size.cy;
end;
end;
if AddForm(hPrinter, 1, @FormInfo1) then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERSIZE;
// PDevMode.dmFields := PDevMode.dmFields or DMBIN_MANUAL;
PDevMode.dmPaperSize :=cReturned + 1;
PDevMode.dmFormName:=CustomFormName;
Printer.PrinterIndex := Printer.PrinterIndex;
Result := True;
end;
end;
finally
FreeMem(pForm);
end;
end;
end;
var
Device, Driver, Port: array[0..127] of char;
hDevMode: THandle;
PDevMode: PDeviceMode;
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, hDevMode);
if hDevMode <> 0 then
begin
PDevMode := GlobalLock(hDevMode);
try
if isrect then
PDevMode^.dmorientation := dmorient_landscape
else
PDevMode^.dmorientation := dmorient_portrait;
if (Win32Platform = VER_PLATFORM_WIN32s) or
(Win32Platform = VER_PLATFORM_WIN32_WINDOWS) then
Win95SetForm(PDevMode)
else
if Win32Platform = VER_PLATFORM_WIN32_NT then
WinNTSetForm(PDevMode, Device, Port);
Printer.SetPrinter(Device, Driver, Port,hDevMode);
finally
GlobalUnlock(hDevMode);
end;
end ;
end;