In .NET, the PrintPageEventArgs.HasMorePage property must be used to send the form feed to the printer. By calling e.Graphics.DrawString ("\ f", sFont, sBrush, 0, 0), you simply render the text for the printed document, which the printer will never interpret as a feed.
Since you know where you want to split the page, instead of calling the InserPageBreak method, set PrintPageEventArgs.HasMorePages = true to the PrintPage event handler. This will send the form feed to the printer and your PrintPage event will continue until you set HasMorePages = false.
Hope this helps. It may be useful to know how you applied the PrintPage event handler.
Example:
Use the BeginPrint handler to initialize data before printing.
void _document_BeginPrint(object sender, PrintEventArgs e) { //generate some dummy strings to print _pageData = new List<string>() { "Page 1 Data", "Page 2 Data", "Page 3 Data", }; // get enumerator for dummy strings _pageEnumerator = _pageData.GetEnumerator(); //position to first string to print (ie first page) _pageEnumerator.MoveNext(); }
In the PrintPage handler, print one page at a time and set HasMorePages to indicate if there is another page to print. In this example, three pages will print, one line on each page. After the third page, _pageEnumerator.MoveNext () will return false, completing the print job.
void _document_PrintPage(object sender, PrintPageEventArgs e) { Font sFont = new Font("Arial", 10); Brush sBrush = Brushes.Black;
source share