trichview.com

trichview.support




Re: Setting Printer Paper size...


Return to index


Author

Message

Sergey Tkachenko

Posted: 04/18/2002 14:15:06


Well, how to change the main printer properties from code.


1) Choosing printers

Change Printer.PrinterIndex (see also Printer.Printers)

Printer.PrinterIndex can also be used to determine if any printer is

installed

(if Printer.PrinterIndex=-1, there are no printers, and you should disable

all printing commands)


2) Changing orientation

Assign Printer.Orientation to poLandscape or poPortrait


3) Choosing paper size (from standard sizes)

Can be done with the following procedure:


  procedure SetPaperSize(PaperSize: Integer);

  var ADevice, ADriver, APort: array[0..79] of Char;

      ADeviceMode: THandle;

      DevMode: PDeviceMode;

  begin

    Printer.GetPrinter(ADevice,ADriver,APort,ADeviceMode);

    if ADeviceMode<>0 then begin

      DevMode := PDeviceMode(GlobalLock(ADeviceMode))

      end

    else

      raise Exception.Create('Error initializing printer');

    DevMode.dmFields := DevMode.dmFields or DM_PAPERSIZE;

    DevMode.dmPaperSize := PaperSize;

    GlobalUnlock(ADeviceMode);

    Printer.SetPrinter(ADevice,ADriver,APort,ADeviceMode);

  end;


You can see a list of available paper sizes in Windows API Help (Delphi

menu: Help | Windows SDK).

Search DEVMODE in the help index, then search for DMPAPER_*** constants.


For example,  SetPaperSize(DMPAPER_A4)


Do not forget to call FormatPages after each change in paper size.





Powered by ABC Amber Outlook Express Converter