[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

Setting Printer Margins Programmatically

How can I set the printer margins (left, top, right, bottom) programmatically using C++ (without MFC)? I was able to set the orientation but could not find a way to do it for margins.
1 Solution
Margins are not basic properties of the printer (device). If using a report library (or MFC) you can define margins but they were handled by the document or report format that comes with the library. If not using a report library you have to care for them yourself when printing to the device.

The parameters you could set for a specific printer is in struct DEVMODE:


For a given printer DC (device context) you may retrieve its capabilities by calling GetDeviceCaps.  Here the properties PHYSICALOFFSETX and PHYSICALOFFSETY can be used to find out the 'physical' margins. Logical margins you my calulate by evaluating the values for PHYSICALWIDTH/PHYSICALHEIGHT and LOGPIXELSX/LOGPIXELSY  and HORZRES/VERTRES.

Regards, Alex


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now