Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printpage margins

Posted on 2013-11-20
11
Medium Priority
?
396 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 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