首先,你得先打开你的打印机设备,对吧:
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;
现在,你可以获取打印机的信息了。例如:打印机的定位设置。
if ((DevMode^.dmFields and DM_ORIENTATION) = DM_ORIENTATION) and
(DevMode^.dmOrientation = DMORIENT_LANDSCAPE) then
//Landscape
else
//Portrait
同样,你可以获取纸张的大小、纸张来源、双面打印、、、、