Determine Printer Margins Programmatically
By Sergey - Posted on January 1st, 2008
The GetDeviceCaps function can be used to retrieve printer-specific information as demonstrated below.
| This is sample code. Add error handling and adjust to your requirements as necessary. |
#define LOGPIXELSX 88 && Logical pixels/inch in X #define LOGPIXELSY 90 && Logical pixels/inch in Y #define PHYSICALWIDTH 110 && Physical Width in device units #define PHYSICALHEIGHT 111 && Physical Height in device units #define PHYSICALOFFSETX 112 && Physical Printable Area x margin #define PHYSICALOFFSETY 113 && Physical Printable Area y margin DECLARE Long GetDeviceCaps IN gdi32 Long hDC, Long nIndex DECLARE Long CreateDC IN gdi32 String lpszDriver, String lpszDevice, Long lpszOutput, Long lpInitData DECLARE Long DeleteDC IN gdi32 Long hDC && Use default printer lcPrinter = SET("Printer",3) lnDC = CreateDC("", lcPrinter, 0, 0) lnPixelsPerInchY = GetDeviceCaps(lnDC, LOGPIXELSY) lnPixelsPerInchX = GetDeviceCaps(lnDC, LOGPIXELSX) ? lnPixelsPerInchY, lnPixelsPerInchX lnPrinterMarginLeft = GetDeviceCaps(lnDC , PHYSICALOFFSETX) lnPrinterMarginTop = GetDeviceCaps(lnDC , PHYSICALOFFSETY) lnPrinterMarginLeftInch = lnPrinterMarginLeft / lnPixelsPerInchX lnPrinterMarginTopInch = lnPrinterMarginTop / lnPixelsPerInchY ? lnPrinterMarginTopInch, lnPrinterMarginLeftInch DeleteDC(lnDC)
Recent comments
2 hours 21 min ago
4 days 10 hours ago
4 days 11 hours ago
1 week 10 hours ago
1 week 11 hours ago
2 weeks 1 day ago
2 weeks 1 day ago
2 weeks 4 days ago
2 weeks 4 days ago
2 weeks 6 days ago