private void pDoc_PrintPage(object sender, PrintPageEventArgs e)
{
int charactersOnPage = 0;
int linesPerPage = 0;
if (PrintedSection == "") { PrintedSection = TheOutput; }
// Sets the value of charactersOnPage to the number of characters
// of stringToPrint that will fit within the bounds of the page.
e.Graphics.MeasureString(PrintedSection, this.Font,
e.MarginBounds.Size, StringFormat.GenericTypographic,
out charactersOnPage, out linesPerPage);
// Draws the string within the bounds of the page
e.Graphics.DrawString(PrintedSection, this.Font, Brushes.Black,
e.MarginBounds, StringFormat.GenericTypographic);
// Remove the portion of the string that has been printed.
PrintedSection = PrintedSection.Substring(charactersOnPage);
// Check to see if more pages are to be printed.
e.HasMorePages = (PrintedSection.Length > 0);
}