Setting Printer Margins Programmatically

Posted on 2007-10-16
Last Modified: 2012-06-27
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.
Question by:nabehs
    1 Comment
    LVL 39

    Accepted 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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now