Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
System.Drawing.Printing.PrintDocument p = new System.Drawing.Printing.PrintDocument();
                 p.PrinterSettings.PrinterName = cbInstalledPrinter.Text;

                 char splitter = '\n';
                 char splitter2 = '\r';

                 string[] test1 = txtTextToPrint.Text.Split(splitter);

                 foreach (string s in test1)
                 {
                     Console.WriteLine(s);
                 }

                 p.PrintPage += delegate(object sender1, System.Drawing.Printing.PrintPageEventArgs e1)
                 {
                     float x = 10;
                     float y = 5;
                     float height = 0F;

                      Font drawFont = new Font("Times New Roman", 8, FontStyle.Regular);

                     string[] test = txtTextToPrint.Text.Split(splitter);

                     foreach (string s in test)
                     {
                         string text = s.Trim();
                         e1.Graphics.DrawString(text, drawFont, new SolidBrush(Color.Black), new RectangleF(x, y,
                         p.DefaultPageSettings.PrintableArea.Width, height));
                         y += e1.Graphics.MeasureString(text, drawFont).Height;
                         e1.Graphics.Flush();
                     }
                 };

                 p.Print();


This is what I use to print. But for some odd reason it only prints till the second last line, then when I print again, it first prints the last line and then starts the printing job till the second last line...and so it continues. The printer is connected to LPT2 and needs to work on this port. If it connects to any other port it works perfectly...but we need to use LPT2.

What I have tried:

Flushing the buffer...
Changing the fontStyle
Splitting the lines
Sending to the printer as one formatted string.
Posted
Updated 14-Mar-16 23:50pm

1 solution

Send a couple of blank lines after the actual print.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900