Solved

Printpage margins

Posted on 2013-11-20
11
381 Views
Last Modified: 2013-11-27
How can I absolutely position text on a printed page. The margins of the printpage graphics object are relative to the printer's capability. What I really want is to position the following text exactly 1" from the physical border of the printed page.

e.Graphics.DrawString("TEXT", New Font("Arial", 9), Brushes.Black, New Point(100, 100))

Open in new window


Please note that OriginsAtMargins is not the answser. From MSDN:
Calculating the area available to print requires knowing the physical size of the paper, the margins for the page, and the location of the Graphics object origin. When OriginAtMargins is true, the Graphics object location takes into account the PageSettings.Margins property value and the printable area of the page. When OriginAtMargins is false, only the printable area of the page is used to determine the location of the Graphics object origin, the PageSettings.Margins value is ignored.

Again, what I want is the origin at the physical edge of the page, not the printable area.
0
Comment
Question by:mankowitz
  • 6
  • 4
11 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39665713
It almost sounds like you need to check the hard margins:

PageSettings.HardMarginX Property
http://msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings.hardmarginx(v=vs.110).aspx

The hard margin represents the physical margin set by the printer.
0
 
LVL 16

Expert Comment

by:DansDadUK
ID: 39665764
Perhaps by making use of the PageSettings.HardMarginX, PageSettings.HardMarginY properties (and, perhaps, PageSettings.PrintableArea) ?

I'm putting this forward from a position of ignorance, as I've never used Graphics objects (or VB, come to that).
0
 
LVL 16

Expert Comment

by:DansDadUK
ID: 39665768
Sorry, TheLearnedOne: I was composing my response whilst you were posting yours!
0
 
LVL 24

Author Comment

by:mankowitz
ID: 39669459
Sorry, that doesn't help. Please look at MSDN. The Hard Margins are the printer's maximum capability, not the edge of the page. Soft margins are the margins determined by the software. I want to place items relative to the physical edge of the page.

For example, I have a form that needs to be printed upon. The form may be fed into printers with different hard margins. I want to position things relative to the physical page edge.

Thanks.

Again, what I want is the origin at the physical edge of the page, not the printable area.
0
 
LVL 16

Expert Comment

by:DansDadUK
ID: 39670649
As far as I can make out, the Graphics sub-system won't let you place the origin outside of the printable area of the target device.

But knowing the hard margin value for the current device, you can work out an offset so that all of your measurements can effectively be made relative to the physical edge of the page.

As the hard margin may quite possibly vary from device to device (and with page size), the offset used will also vary, and at any one time will only be correct for the current device.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 24

Author Comment

by:mankowitz
ID: 39671933
dans,

ok, I understand. Can you give me an algorithm for placing objects relative to the physical page edge? How do I know the displacement from the physical page edge to the hard margin?
0
 
LVL 16

Expert Comment

by:DansDadUK
ID: 39671945
The displacement is whatever value is returned by the HardMarginX/Y property, in whatever units those values are given.

So if you set the origin to the hard (not soft) margins, then:
Relative position = physical position - displacement

You obviously have to make sure that all these measurements are using the same units.
0
 
LVL 16

Expert Comment

by:DansDadUK
ID: 39671950
... but bear in mind that with most printers, positions are probably not guaranteed to be more accurate than (say) +/- 2mm, due to mechanical paper path mechanisms.
0
 
LVL 24

Author Comment

by:mankowitz
ID: 39673082
so,

e.Graphics.DrawString("TEXT", New Font("Arial", 9), Brushes.Black, New Point(100 - ps.HardMarginX, 100 - ps.HardMarginY))

is that right?
0
 
LVL 16

Accepted Solution

by:
DansDadUK earned 500 total points
ID: 39674993
Something like that, provided that the various different methods/properties are using the same units (which I assume to be 1/100 inch if the 100 values are supposed to represent 1 inch), and that you've previously set OriginAtMargins to false (only the printable area of the page is used to determine the location of the Graphics object origin).
0
 
LVL 24

Author Closing Comment

by:mankowitz
ID: 39681070
I was hoping for some actual code, verified to be working, but this is a good start.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

864 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

16 Experts available now in Live!

Get 1:1 Help Now