You need to use the Windows API functions OpenPrinter
and GetPrinter
. When calling GetPrinter
, pass it a PRINTER_INFO_2
record, which will be returned with the pDevMode
member set to a DEVMODE
; that DEVMODE
record contains a flag for whether collation is enabled (among other things).
Here's an old Borland NG post by TeamB's Dr. Peter Below. It demonstrates updating printer settings to make them permanent, but it includes using OpenPrinter
, GetPrinter
, ClosePrinter
, and PRINTER_INFO_2
, as well as using the DEVMODE
(referred to as hDevMode
in the code below); it should get you started.
Procedure MakePrintersettingsPermanent;
var
hPrinter: THandle;
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDeviceMode: THandle;
pDevMode: PDeviceMode;
bytesNeeded: Cardinal;
pPI: PPrinterInfo2;
Defaults: TPrinterDefaults;
retval: BOOL;
begin
Assert( Printer.PrinterIndex >= 0 );
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
FillChar( Defaults, Sizeof(Defaults), 0 );
Defaults.DesiredAccess:=
PRINTER_ACCESS_ADMINISTER or PRINTER_ACCESS_USE;
if not WinSpool.OpenPrinter(@Device, hPrinter, @Defaults ) then
RaiseLastWin32Error;
try
retval := WinSpool.GetPrinter(
hPrinter,
2,
Nil, 0, @bytesNeeded );
GetMem( pPI, bytesNeeded );
try
retval := WinSpool.GetPrinter(
hPrinter, 2,
pPI, bytesNeeded, @bytesNeeded );
If not retval Then
RaiseLastWin32Error;
pDevMode := GlobalLock( hDeviceMode );
Assert( Assigned( pdevmode ));
try
Move( pdevmode^, pPI^.pDevMode^, Sizeof( pdevmode^ ));
finally
GlobalUnlock( hDevicemode );
end;
If not WinSpool.SetPrinter(
hPrinter, 2,
pPI,
0 )
Then
RaiseLastWin32error;
finally
FreeMem( pPI );
end;
finally
WinSpool.ClosePrinter( hPrinter );
end;
end;