Link to home
Start Free TrialLog in
Avatar of Levente
Levente

asked on

Query page size BEFORE printing

I need to know the width and height (in pixels) of the page which in my printer. Delphi provides a way to query it:
Printer.PageWidth and Printer.PageHeight contains the above values of the page which is BEING printed.

How can I query the size in pixels of the selected page in the selected printer BEFORE Printer.StartDoc?

Thank you,
Levente
Avatar of Lischke
Lischke

Hi Levente,

try out this code:

procedure TMainForm.Button7Click(Sender: TObject);

var
  Buffer: array[0..255] of Char;
  DeviceMode: THandle;
  DevMode: PDevMode;

begin
  Printer.GetPrinter(Buffer, Buffer, Buffer, DeviceMode);
  DevMode := GlobalLock(DeviceMode);
  ShowMessage(IntToStr(DevMode.dmPaperWidth));
  GlobalUnlock(DeviceMode);
end;

Ciao, Mike
Listening
Avatar of Levente

ASKER

Mike,

I'm affraid, I must reject your answer. This call queries the PHYSICAL size of the page in tenths of milimetes. I need the logical one in pixels.

Br,
Levente
Hi Levente,

You can use the DevMode.dmPelsWidth and DevMode.dmPelsHeight fields to find this out.

Cheers,

Raymond.
ASKER CERTIFIED SOLUTION
Avatar of Lischke
Lischke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Mike: What about the DevMode.dmPelsWidth and DevMode.dmPelsHeight fields?

Cheers,

Raymond.
They do not contain useful values (equal to 0)...
Avatar of Levente

ASKER

Thank you for your code. It finally works.
Glad to help.

Ciao, Mike