Printing Delphi

Title: to get a printer settings
Question: How can I receive a current printer settings?
Answer:
At first, you must open the printer device:
var
FDevice: PChar;
FDriver: PChar;
FPort: PChar;
DeviceMode: THandle;
DevMode: PDeviceMode;
procedure OpenThePrinterDevice;
var
Driver_Info2: PDriverInfo2;
Retrieved: dword;
hPrinter: THandle;
begin
Printer().GetPrinter(FDevice, FDriver, FPort, DeviceMode);
if DeviceMode = 0 then
Printer().GetPrinter(FDevice, FDriver, FPort, DeviceMode);
OpenPrinter(FDevice, hPrinter, nil);
GetMem(Driver_Info2, 255);
GetPrinterDriver(hPrinter, nil, 2, Driver_info_2, 255, Retrieved);
StrLCopy(FDriver, PChar(ExtractFileName(StrPas(Driver_Info2^.PDriverPath))
+ #0), 63);
FreeMem(Driver_info_2, 255);
DevMode := GlobalLock(DeviceMode);
end;
And now you can get the information from printer. For example, the orientation settings:
if ((DevMode^.dmFields and DM_ORIENTATION) = DM_ORIENTATION) and
(DevMode^.dmOrientation = DMORIENT_LANDSCAPE) then
//Landscape
else
//Portrait
Also you can detect a paper size, paper source, print duplex and quality etc. View a const description in Windows.pas.
At last, don't forget to unlock a device:
GlobalUnlock(DeviceMode);