From: Peter Below (TeamB) <100113.1101@compuXXserve.com> Subject: Re: How to print to select custom paper sizes when printing Date: 14 Mar 2000 00:00:00 GMT Message-ID: Content-Transfer-Encoding: 8bit References: <8alnuf$qop3@bornews.borland.com> Content-Type: text/plain; charset=iso-8859-1 X-Trace: 14 Mar 2000 13:38:26 -0800, 193.159.117.235 Organization: TeamB Mime-Version: 1.0 Reply-To: 100113.1101@compuXXserve.com Newsgroups: borland.public.delphi.winapi In article <8alnuf$qop3@bornews.borland.com>, Mille Eriksson wrote: > > How do I select a custom paper size programmatically when printing in > Delphi? > Set printer paper size. See win32.hlp entry for DEVMODE for a list of valid paper format ids. var Device, Driver, Port: array[0..80] of Char; DevMode: THandle; pDevmode: PDeviceMode; begin // Get printer device name etc. Printer.GetPrinter(Device, Driver, Port, DevMode); // force reload of DEVMODE Printer.SetPrinter(Device, Driver, Port, 0) ; // get DEVMODE handle Printer.GetPrinter(Device, Driver, Port, DevMode); If Devmode <> 0 Then Begin // lock it to get pointer to DEVMODE record pDevMode := GlobalLock( Devmode ); If pDevmode <> Nil Then try With pDevmode^ Do Begin // modify paper size dmPapersize := DMPAPER_A4; // tell printer driver that dmPapersize field contains // data it needs to inspect. dmFields := dmFields or DM_PAPERSIZE; End; finally // unlock devmode handle. GlobalUnlock( Devmode ); end; End; { If } end; This gives the general strategy for changing printer parameters which are not directly exposed by the Printer object. To set a custom paper size in Win9x you use DMPAPER_USER and set the dmPaperwidth and dmPaperHeight fields of the DEVMODE (and also OR the matching flags into dmFields!). On NT the process is different. Here you have to define a custom "form" for the printer (see AddForm, WinSpool unit) and then give the name of the form in the DEVMODES dmFormname field (again setting the matching flag in dmFields). Peter Below (TeamB) 100113.1101@compuserve.com) No replies in private e-mail, please, unless explicitly requested!