I am trying to do a form feed & skip 1 page while printing, however with the below lines of code, i am not able to make a form feed.
private void InserPageBreak(System.Drawing.Printing.PrintPageEventArgs e)
{
Font sFont = new Font("Arial", 10);
Brush sBrush = Brushes.White;
e.Graphics.DrawString("\f", sFont, sBrush, 0, 0);
}
I use PrintDialog to print the page contents. I am using “\f” C#’s form feed character.
Any thoughts on how to implement/make this form feed to work ?
PS: I even tried this:
//ASCII code 12 – printer’s form feed control code.
string test = char.ConvertFromUtf32(12);
e.Graphics.DrawString(test, sFont, sBrush, 0, 0);
internally c# converts that to “\f”, but didn’t do form feed, anyone who has implemented “\f”, please share your thoughts.
In .NET, the PrintPageEventArgs.HasMorePage property should be used to send a form feed to the printer. By calling e.Graphics.DrawString(“\f”, sFont, sBrush, 0, 0), you are simply rendering text to the document to be printed, which will never be interpreted by the printer as a form feed.
Since you know where you want to break the page, instead of calling your InserPageBreak method, set PrintPageEventArgs.HasMorePages = true within your PrintPage event handler. That will send a form feed to the printer and your PrintPage event will continue to be fired until you set HasMorePages = false.
I hope this helps. It may be useful to see how you have implemented your PrintPage event handler.
Example:
Use the BeginPrint handler to initialize data before printing
In the PrintPage handler, print a single page at a time, and set HasMorePages to indicate whether or not there is another page to print. In this example, three pages will print, one string on each page. After the 3rd page, _pageEnumerator.MoveNext() will return false, ending the print job.