• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

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
0
Levente
Asked:
Levente
  • 4
  • 3
  • 2
1 Solution
 
LischkeCommented:
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
0
 
rwilson032697Commented:
Listening
0
 
LeventeAuthor Commented:
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
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
rwilson032697Commented:
Hi Levente,

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

Cheers,

Raymond.
0
 
LischkeCommented:
Ok, I didn't prove the pixel resolution and unfortunately the devmode structure gives no information about the resolution (at least as it is at the moment). A more general approach is to use a socalled information context which is kinda stripped down version of a device context:

procedure TMainForm.Button7Click(Sender: TObject);

var
  Driver,
  Device,
  Port: array[0..128] of Char;
  DeviceMode: THandle;
  IC: HDC;
  W, H,
  LogX,
  LogY: Integer;

begin
  Printer.GetPrinter(Device, Driver, Port, DeviceMode);
  IC := CreateIC(Driver, Device, Port, nil);
  W := GetDeviceCaps(IC, HORZRES);
  H := GetDeviceCaps(IC, VERTRES);
  LogX := GetDeviceCaps(IC, LOGPIXELSX);
  LogY := GetDeviceCaps(IC, LOGPIXELSY);
  DeleteDC(IC);
end;

This should finally give you not only the information you want at the moment but all you can expect from a DC.

Ciao, Mike
0
 
rwilson032697Commented:
Mike: What about the DevMode.dmPelsWidth and DevMode.dmPelsHeight fields?

Cheers,

Raymond.
0
 
LischkeCommented:
They do not contain useful values (equal to 0)...
0
 
LeventeAuthor Commented:
Thank you for your code. It finally works.
0
 
LischkeCommented:
Glad to help.

Ciao, Mike
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now