A little background: Creating a program that generates reports and forms from database inputs. I have everything up and running just fine, but I cannot seem to figure out my printing issue. I have tried several methods for printing to a printer and every document that I print from my custom program is slightly off-center to the right on the page.
I understand the reason for this is the printer itself, but how can I accomodate for this? In print preview the report looks perfect. I need some guidance on what methods will work across multiple, varied, printers in VB.NET. Any help is greatly appreciated.
Instead of using e.pagebounds for the bounding box, try using e.graphics.VisibleClipBounds. Some printer drivers are a little unreliable with the e.pagebounds, and the visibleclipbounds seems more accurate.
For example:
Sub printPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
Dim g As Graphics
g = e.Graphics
g.ResetTransform()
g.VisibleClipBounds is now a rectangle that should be the maximum page size, and can be used for centering text or graphics. Just use g as the graphics object for outputting to the printer. The horizontal center of the page is
g.VisibleClipBounds.Left + g.VisibleClipBounds.Width / 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With