protected virtual void printDocument_PrintPage(object sender, PrintPageEventArgs e) {
Graphics g = e.Graphics;
// Approximate the printable area of the page. This approximation assumes
// the unprintable margins are distributed equally between the left and right,
// and top and bottom sides. To exactly determine the printable area, you
// must resort to the Win32 API.
RectangleF displayRect = new RectangleF(
e.MarginBounds.Left -
(e.PageBounds.Width - g.VisibleClipBounds.Width) / 2,
e.MarginBounds.Top -
(e.PageBounds.Height - g.VisibleClipBounds.Height) / 2,
e.MarginBounds.Width, e.MarginBounds.Height);
ScaleAndDraw(g, displayRect);
}