<p>What's the easiest way to add a header and footer to a .Net PrintDocument object, either pragmatically or at design-time?</p>

<p>Specifically I'm trying to print a 3rd party grid control (Infragistics GridEx v4.3), which takes a PrintDocument object and draws itself into it.</p>

<p>The resulting page just contains the grid and it's contents - however I would like to add a header or title to identify the printed report, and possibly a footer to show who printed it, when, and ideally a page number and total pages.</p>

<p>I'm using VB.Net 2.0.</p>

<p>Thanks for your help!</p>

[{'answer_id': 61809, 'author': 'Booji Boy', 'author_id': 1433, 'author_profile': 'https://Stackoverflow.com/users/1433', 'pm_score': 3, 'selected': True, 'text': '<p>The printdocument object fires the printpage event for each page to be printed. You can draw text/lines/etc into the print queue using the printpageeventargs event parameter: </p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx</a></p>\n\n<p>Dim it WithEvents when you pass it to the grid, so you can handle the event. </p>\n'}, {'answer_id': 224934, 'author': 'Andrew', 'author_id': 5662, 'author_profile': 'https://Stackoverflow.com/users/5662', 'pm_score': 3, 'selected': False, 'text': '<p>Following <a href="https://stackoverflow.com/questions/59213/easiest-way-to-add-a-header-and-footer-to-a-printingprintdocument-net-20#61809">booji-boy</a>\'s answer, here\'s what I came up with (which I\'ve simplified for example purposes):</p>\n\n<pre><code>Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click\n\n        Dim oDoc As New Printing.PrintDocument\n        oDoc.DefaultPageSettings.Landscape = True\n        AddHandler oDoc.PrintPage, AddressOf PrintPage\n\n        oDoc.DocumentName = "Printout"\n\n        InfragisticsWinGrid.PrintPreview(InfragisticsWinGrid.DisplayLayout, oDoc)\n\n    End If\nEnd Sub\n\n\nPrivate Sub PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)\n\n    \' Draw title\n    e.Graphics.DrawString("Report Title"), New Font("Arial", 16), Brushes.Black, 95, 70)\n\n    \' Draw footer\n    e.Graphics.DrawImage(DirectCast(mResources.GetObject("footer_logo"), Drawing.Bitmap), 95, e.PageBounds.Height - 87)\n    Dim drawFont As New Font("Arial", 8.75)\n\n    e.Graphics.DrawString("Report Title", drawFont, Brushes.Gray, 190, e.PageBounds.Height - 90)\n    e.Graphics.DrawString("Printed", drawFont, Brushes.Gray, 190, e.PageBounds.Height - 76)\n    e.Graphics.DrawString("Printed By", drawFont, Brushes.Gray, 190, e.PageBounds.Height - 62)\n\n    \' Draw some grid lines to add structure to the footer information\n    e.Graphics.DrawLine(Pens.Gray, 246, e.PageBounds.Height - 90, 246, e.PageBounds.Height - 48)\n    e.Graphics.DrawLine(Pens.Gray, 188, e.PageBounds.Height - 75, 550, e.PageBounds.Height - 75)\n    e.Graphics.DrawLine(Pens.Gray, 188, e.PageBounds.Height - 61, 550, e.PageBounds.Height - 61)\n\n    e.Graphics.DrawString("Report", drawFont, Brushes.Black, 250, e.PageBounds.Height - 90)\n    e.Graphics.DrawString(Date.Now.ToShortDateString &amp; " " &amp; Date.Now.ToShortTimeString, drawFont, Brushes.Black, 250, e.PageBounds.Height - 76)\n    e.Graphics.DrawString("Andrew", drawFont, Brushes.Black, 250, e.PageBounds.Height - 62)\n\nEnd Sub\n</code></pre>\n\n<p>I had to play with the values of <code>e.PageBounds.Height - x</code> to get the drawn items to line up.</p>\n\n<p>Thanks again <a href="https://stackoverflow.com/users/1433">Booji Boy</a> for the pointer - getting at the ReportPage.Graphics() was exactly what I was after  :o)</p>\n'}]
['https://Stackoverflow.com/questions/59213', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5662/']