2010-12-05 9 views
1

가상 PDF 프린터 드라이버 (FoxitPDF 작성기, 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 이상으로 이미 증가되어 빈 페이지 만 생성합니다.