Getting the -REAL- printable area of a page
-
Hi all, to get the real printable area of a page (on a printer of course) is it correct to do it like this? assuming that i want to use HIMETRIC, mydc is a device context (CDC class), and it has allready been "opened" to my printer... dc.SetMapMode(MM_HIMETRIC); CSize pagesize; // get the "physical" size of the page... pagesize.cx=dc.GetDeviceCaps(PHYSICALWIDTH); pagesize.cy=dc.GetDeviceCaps(PHYSICALHEIGHT); // now take off the non printable area pagesize.cx-=dc.GetDeviceCaps(PHYSICALOFFSETX); pagesize.cy-=dc.GetDeviceCaps(PHYSICALOFFSETY); // returned values were in device units, we need himetric dc.DPtoHIMETRIC(&pagesize); // pagesize now has the real printable area of the page is this correct? is there a better way? thanks!
-
Hi all, to get the real printable area of a page (on a printer of course) is it correct to do it like this? assuming that i want to use HIMETRIC, mydc is a device context (CDC class), and it has allready been "opened" to my printer... dc.SetMapMode(MM_HIMETRIC); CSize pagesize; // get the "physical" size of the page... pagesize.cx=dc.GetDeviceCaps(PHYSICALWIDTH); pagesize.cy=dc.GetDeviceCaps(PHYSICALHEIGHT); // now take off the non printable area pagesize.cx-=dc.GetDeviceCaps(PHYSICALOFFSETX); pagesize.cy-=dc.GetDeviceCaps(PHYSICALOFFSETY); // returned values were in device units, we need himetric dc.DPtoHIMETRIC(&pagesize); // pagesize now has the real printable area of the page is this correct? is there a better way? thanks!
In some, if not most cases, I have found that the PHYSICALOFFSETX and PHYSICALOFFSETY would apply to BOTH edges of the page, so you might want to do your math like this: // now take off the non printable area pagesize.cx-= (2 * dc.GetDeviceCaps(PHYSICALOFFSETX)); pagesize.cy-= (2 * dc.GetDeviceCaps(PHYSICALOFFSETY)); I also don't think this accounts for any of the margins the user might have set for the printing area. You might want to also obtain the printer device context (CreateDC) and examine the DEVMODE fields: dmYResolution - Specifies the y-resolution, in dots per inch, of the printer. If the printer initializes this member, the dmPrintQuality member specifies the x-resolution, in dots per inch, of the printer. Or you can get the from associated with a print job and check these fields: Size - Specifies the width and height, in thousandths of millimeters, of the form. ImageableArea - Specifies the width and height, in thousandths of millimeters, of the form.