Form feed in C # print

I am trying to feed the form and skip 1 page while printing, however with the lines of code below I cannot create the form.

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 contents of a page. I use the feed character "\ f" C #.

Any thoughts on how to implement / make this form work?

PS: I even tried this:

// ASCII code 12 is the feed control code for the printer form.

  string test = char.ConvertFromUtf32(12); e.Graphics.DrawString(test, sFont, sBrush, 0, 0); 

C # internally converts it to "\ f", but does not execute the feed form, anyone who has implemented "\ f" share your thoughts.

+6
source share
1 answer

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; //print current page e.Graphics.DrawString(_pageEnumerator.Current, sFont, sBrush, 10, 10); // advance enumerator to determine if we have more pages. e.HasMorePages = _pageEnumerator.MoveNext(); } 
+5
source

Source: https://habr.com/ru/post/915854/


All Articles