2008年7月12日

プリンタの用紙のサイズおよび方向を変更

プリンタの用紙のサイズおよび方向を変更するときはGetPrinter/SetPrinterを使用します。
uses
  Printers;

var
  Device: array [0..127] of Char;
  Driver: array [0..127] of Char;
  Port: array [0..127] of Char;
  DeviceMode: THandle;
  pDevMode: ^TDevMode;
begin

  { Lock }
  Printer.GetPrinter(Device,Driver,Port,DeviceMode);
  pDevMode := GlobalLock(DeviceMode);
  try
    { Set paper orientation }
    pDevMode^.dmOrientation := DMORIENT_PORTRAIT;  // 用紙は縦

    { Set paper size }
    pDevMode^.dmPaperSize := DMPAPER_A4;  // 用紙はA4

  finally
    { Unlock }
    GlobalUnlock(DeviceMode);
  end;

  Printer.SetPrinter(Device,Driver,Port,DeviceMode);

end;

元ねたはDelphi Graphic Secrets Know-how & Libraries(中村 拓男著/ソフトバンクパブリッシング/ISBN4-7973-1922-4)。

0 件のコメント: