Solved

Printpage margins

Posted on 2013-11-20
11
383 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

825 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