Board index » delphi » Printers Default page size is not changing

Printers Default page size is not changing

Please give a solution for this problem

I want to use two printers are used in an application. One is the default
Printer with paper size 8.5 x 12 inches(Printer Index 1) and other one is a
paper setting of 8.5 x 4 inches(Printer Index 0).
While changing from first one to second one from with in the application the
paper size is still taken as 8.5 x 12 inches.

I used this code for changing printer
Printer.PrinterIndex:=0;

Which is the correct way of changing the printer?
How can I solve this problem?

Fither
fithe...@hotmail.com

 

Re:Printers Default page size is not changing


Quote
> I want to use two printers are used in an application. One is the default
> Printer with paper size 8.5 x 12 inches(Printer Index 1) and other one is a
> paper setting of 8.5 x 4 inches(Printer Index 0).
> While changing from first one to second one from with in the application the
> paper size is still taken as 8.5 x 12 inches.

> I used this code for changing printer
> Printer.PrinterIndex:=0;

> Which is the correct way of changing the printer?

This is the correct way but there is a bug in the Printers unit (i don't
know which exactly) which sometimes lets it pick up the properties of the
default printer instead of the one you select.

Try this as workaround:

Var
  Device : array[0..255] of char;
  Driver : array[0..255] of char;
  Port   : array[0..255] of char;
  hDeviceMode: THandle;
begin
  Printer.PrinterIndex := 0;
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
  Printer.SetPrinter(Device, Driver, Port, 0 );
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);

The SetPrinter statement should force a complete reload of the printers
TDeviceMode record.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Other Threads