Click here to Skip to main content
15,881,838 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
When i set a range while printing eg.from page no 2 to page no 3 and there are total 4 pages in document, then total no of printed pages comes 4 with page no 1 and page 4 as blank, and page no 2 and 3 as printed.
how can i remove those two blank pages.
my code
C#
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            float linesPerPage = 0;
            float yPos = 0;
            int count = 0;
            float leftMargin = ev.MarginBounds.Left;
            float topMargin = ev.MarginBounds.Top;

            string line = null;

            // Calculate the number of lines per page...
            linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
            if ((range.Checked == true && int.Parse(Startrange.Text) > page))
            {

                while (count < linesPerPage && ((line = streamToPrint.ReadLine()) != null))
                {
                    count++;
                }

            }
            // Print each line of the file...
            if ((all.Checked == true) || (range.Checked == true && int.Parse(Startrange .Text) <= page))
            {
                while (count < linesPerPage && ((line = streamToPrint.ReadLine()) != null))
                {
                    yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
                    ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin,
                        yPos);
                    count++;
                }
            }
            // If more lines exist, print another page...
            if (range.Checked == true && page == int.Parse(Endrange .Text))
            {
                ev.HasMorePages = false;
                return;
            }
            ev.HasMorePages = true;
            page++;
            if ((line != null) && (all.Checked == true))
                ev.HasMorePages = true;
            if ((line == null) && (all.Checked == true))
                ev.HasMorePages = false;
        }
Posted

1 solution

overrite the on the page which remains blank while creating
 
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