Click here to Skip to main content
Rate this: bad
good
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 685
1 Manas Bhardwaj 380
2 OriginalGriff 344
3 Abhinav S 293
4 Sampath Lokuge 245
0 Sergey Alexandrovich Kryukov 7,967
1 OriginalGriff 4,332
2 Peter Leow 3,699
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid