Solved

Printpage margins

Posted on 2013-11-20
11
384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

740 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