Click here to Skip to main content
12,251,445 members (66,805 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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
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 24-Jan-13 17:34pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

overrite the on the page which remains blank while creating
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100