2010-12-05 20 views
1

Virtual PDF Printerドライバ(FoxitPDF Writer、doPDF、NovaPDFなど)でいくつかのページを印刷しようとしています。.net 2.0 PrintDocumentの問題

ほとんど印刷されません。ほとんどの場合、ページは空白です。 MS Wordから文書を印刷しようとした場合は、このようなことはありません。

なぜですか?問題を解決するにはどうすればよいですか?

これは私のコードです:

void printDoc_PrintPage(object sender, PrintPageEventArgs e) 
     { 
      if (_studentsList != null) 
      { 
       Graphics g = e.Graphics; 
       PointF point = new PointF(0, yStudentTopMargin); 

       int count = 2; 

       while (true) 
       { 
        if ((count == 0) || (_listItemCount > _studentsList.Count - 1)) 
        { 
         break; 
        } 

        StudentDrawer.DrawStudent(g, point, _studentsList[_listItemCount], xStudentBoxDistance, yStudentBoxDistance, xLineDistance, yLineDistance); 

        point.Y += (yStudentBoxDistance * 10); 

        count--; 
        _listItemCount++; 
       } 

       if (_listItemCount < _studentsList.Count) 
       { 
        e.HasMorePages = true; 
       } 
       else 
       { 
        e.HasMorePages = false; 
       } 
      } 
      else 
      { 
       return; 
      } 
     } 

public static void DrawStudent(Graphics g, PointF point, Student std, int xBoxDistance, int yBoxDistance, int xLineDistance, int yLineDistance) 
     { 
      SolidBrush brush = new SolidBrush(Color.Black); 
      Font boldFont = new Font("Times New Roman", yLineDistance * 2/3, FontStyle.Bold); 
      Font normalFont = new Font("Arial", yLineDistance * 2/3); 
      Pen pen = new Pen(brush); 

      const int fontSize = 10; 

      float x = point.X; 
      float y = point.Y; 

      float leftMargin = xBoxDistance;//175; 
      //const float rightMargin = 100; 
      float topMargin = yBoxDistance;//60; 
      //const float bottomMargin = 100; 

      StringDrawer.DrawRoll(g, "Roll No. :", std.RollNo.ToString(), fontSize + 2, x + leftMargin, y + topMargin , xLineDistance, yLineDistance); 
      StringDrawer.DrawHeading(g, "SUBJECT", "MARKS", "L. GRADE", "GP", fontSize, x + leftMargin, y + topMargin + (1 * yLineDistance), xLineDistance, yLineDistance); 
       ...... ... ... ... 
     ...... ... ... ... 
      StringDrawer.DrawSubject(g, "Total", std.Bangla1stPaper_Marks.ToString(), std.Bangla1stPaper_GradeLetter, std.Bangla1stPaper_GradePoint.ToString(), fontSize, x + leftMargin, y + topMargin + (15 * yLineDistance), xLineDistance, yLineDistance); 
     } 

public static void DrawHeading(Graphics g, string subject, string marks, string letterGrade, string gp, int fontSize, float x, float y, int xDistance, int yDistance) 
     { 
      SolidBrush brush = new SolidBrush(Color.Black); 
      Font boldFont = new Font("Times New Roman", fontSize, FontStyle.Bold); 
      Pen pen = new Pen(brush); 

      g.DrawRectangle(pen, x, y, xDistance, fontSize + 8); 
      g.DrawString(subject, boldFont, brush, x + (0 * xDistance * 1.2f), y); 

      g.DrawRectangle(pen, x + (1 * xDistance), y, xDistance, fontSize + 8); 
      g.DrawString(marks, boldFont, brush, x + (1 * xDistance * 1.3f), y); 

      g.DrawRectangle(pen, x + (2 * xDistance), y, xDistance, fontSize + 8); 
      g.DrawString(letterGrade, boldFont, brush, x + (2 * xDistance * 1.1f), y); 

      g.DrawRectangle(pen, x + (3 * xDistance), y, xDistance, fontSize + 8); 
      g.DrawString(gp, boldFont, brush, x + (3 * xDistance * 1.14f), y); 
     } 

答えて

2

コードは大丈夫に見えます。ただし、BeginPrintイベントハンドラがありません。 _listItemCount変数を0に戻す必要があります。それがなければ、最初のプリントアウトだけが動作し、それ以降のプリントは、_listItemCountが_studentsList.Countを超えて既にインクリメントされているため、空のページしか生成されません。