My application draws charts in a Windows Metafile. Users need to be able to print the charts nicely centered on the page. Quick rundown of printing code:
Private Sub PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
Dim header As Imaging.MetafileHeader = metafile.GetMetafileHeader()
Dim sz As New SizeF(100 * header.Bounds.Width / header.DpiX, 100 * header.Bounds.Height / header.DpiY)
Dim p As New PointF((e.PageBounds.Width - sz.Width) / 2, (e.PageBounds.Height - sz.Height) / 2)
e.Graphics.DrawImage(metafile, p)
End Sub
If I print to a PDF, this looks perfect. But if I print to an actual printer it is off center, about 1/8 of an inch down and to the right. I did a quick experiment to see where the PageBounds were by doing
e.Graphics.DrawRectangle(Pens.Red, e.PageBounds)
and the results were the same, slightly off center. On the PDF this draws a rectangle on the very edge of the page. For what its worth, I have tested on a Toshiba e-Studio 3510c and a HP LaserJet 4000 with the same results. Any help is appreciated, this has been plaguing me for weeks.
Update:
I ended up using e.PageSettings.PrintableArea, but it looks like e.Graphics.VisibleClipBounds gets you the same values as per xpda's answer.