Solved

Printpage margins

Posted on 2013-11-20
11
379 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

759 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

17 Experts available now in Live!

Get 1:1 Help Now