2007. szeptember 20., csütörtök

How to set the printer paper size (2)


Problem/Question/Abstract:

How I can select the printer's papersource through code? How I can read the printer default setting papersource in my Delphi program?

Answer:

{ ... }
var
  aDrvName, aPrtName, aPortName: array[0..127] of Char;
  aDeviceMode: THandle;
  PDevMode: ^TDevMode;
  i: Integer;
begin
  with Printer do
  begin
    GetPrinter(aDrvName, aPrtName, aPortName, aDeviceMode);
    PDevMode := GlobalLock(aDeviceMode);
    try
      if PDevMode^.dmPaperSize = DMPAPER_A4 then
        ShowMessage('A4')
      else if PDevMode^.dmPaperSize = DMPAPER_A3 then
        ShowMessage('A3')
      else
      begin
        ShowMessage('Size not supported!' + #13 + 'Resetting papersize to A4');
        PDevMode^.dmPaperSize := DMPAPER_A4;
      end;
    finally
      GlobalUnlock(aDeviceMode);
    end;
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése