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;
 
<pre>
        string line = null;
 
        // Calculate the number of lines per page...
        linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
        if ((range.Checked == true &amp;&amp; int.Parse(Startrange.Text) &gt; page))
        {
 
            while (count &lt; linesPerPage &amp;&amp; ((line = streamToPrint.ReadLine()) != null))
            {
                count++;
            }
 
        }
        // Print each line of the file...
        if ((all.Checked == true) || (range.Checked == true &amp;&amp; int.Parse(Startrange .Text) &lt;= page))
        {
            while (count &lt; linesPerPage &amp;&amp; ((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 &amp;&amp; page == int.Parse(Endrange .Text))
        {
            ev.HasMorePages = false;
            return;
        }
        ev.HasMorePages = true;
        page++;
        if ((line != null) &amp;&amp; (all.Checked == true))
            ev.HasMorePages = true;
        if ((line == null) &amp;&amp; (all.Checked == true))
            ev.HasMorePages = false;
    }</pre>
Posted 24-Jan-13 18: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
0 OriginalGriff 638
1 Sergey Alexandrovich Kryukov 445
2 ProgramFOX 275
3 CHill60 225
4 Maciej Los 215
0 OriginalGriff 550
1 Sergey Alexandrovich Kryukov 470
2 Maciej Los 310
3 ProgramFOX 275
4 Peter Leow 250


Advertise | Privacy | Mobile
Web01 | 2.8.150331.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2015
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