Using System.Drawing.Printing, I want to print a set of lines in a print document. But the problem is that it prints every line on the very first page, whatever the coordinates are, also if I draw an image. He prints it on one page no matter how large it is.
The following is what I did to print text on multiple pages:
protected void ThePrintDocument_PrintPage (object sender, System.Drawing.Printing.PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPosition = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
Font printFont = this.richTextBox1.Font;
SolidBrush myBrush = new SolidBrush(Color.Black);
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
while(count < linesPerPage && ((line=myReader.ReadLine()) != null))
{
yPosition = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat());
count++;
}
if(line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
myBrush.Dispose();
}
What should I do to print a line on several pages, i.e. the following code should print on two pages, since the line length is 1400 and the length of the print document is 1100, so the remaining 300 lines should be printed on the next page
protected void ThePrintDocument_PrintPage (object sender, System.Drawing.Printing.PrintPageEventArgs ev)
{
Pen P1 = new Pen(Brushes.Violet, 5);
ev.Graphics.DrawLine(P1, new Point(0,0), new Point(500,1400));
}
source