2006. július 2., vasárnap

Set a Printer to Duplex Mode

Problem/Question/Abstract:

How to set a printer to duplex mode?

Answer:

You typically switch a printer to duplex mode by changing its TDeviceMode(API: DEVMODE)record .But first you should test whether the installed printer driver supports this:

uses
printers, winspool;

function PrinterSupportsDuplex: Boolean;
var
Device, Driver, Port: array[0..255] of Char;
hDevMode: THandle;
begin
Printer.GetPrinter(Device, Driver, Port, hDevmode);
Result := WinSpool.DeviceCapabilities(Device, Port, DC_DUPLEX, nil, nil) <> 0;
end;

If it does you can try to switch the duplex mode on before you call  richedit.print:

var
Device, Driver, Port: array[0..80] of Char;
DevMode: THandle;
pDevmode: PDeviceMode;
begin
// Get printer device mode handle.
Printer.GetPrinter(Device, Driver, Port, DevMode);
if Devmode <> 0 then
begin
// lock it to get pointer to DEVMODE record
pDevMode := GlobalLock(Devmode);
if pDevmode <> nil then
try
with pDevmode^ do
begin
dmDuplex := DMDUP_VERTICAL;
dmFields := dmFields or DM_DUPLEX;
end;
finally
// unlock devmode handle.
GlobalUnlock(Devmode);
end;
end; { If }
end;


Nincsenek megjegyzések:

Megjegyzés küldése