여러 페이지를 인쇄하는 데 어려움을 겪고 있습니다. 내 응용 프로그램은 1 - 10 개의 요소가 들어있는 Object type List를 만듭니다. 각 객체는 2 개의 문자열 속성 인 docTypeNumber와 docTypeDescription을 포함합니다. flightnumber라는 변수도 클래스 생성자로 전달됩니다. 각 인스턴스는 문서 유형 번호, 설명 및 항공편 번호가 들어있는 별도의 바코드 시트로 인쇄해야하는 문서 유형입니다. 대부분의 여러 페이지 인쇄 예제는 여러 개별 페이지로 구성된 doument가 아닌 여러 페이지에 "흘러 넘치는"한 문서입니다. 내 질문은 어떻게 이것을 달성하는 것입니다.목록에서 여러 페이지 인쇄에 도움이 필요합니다.
여러 페이지로 큰 문서를 만들어야하나요? PrintDocument 클래스의 인스턴스를 여러 개 만들어야합니까?
도움을 주시면 감사하겠습니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace BarcodeTest
{
class BarcodePrinter
{
public BarcodePrinter(List<DocumentType> type, string flightnumber)
{
docType = type;
flightNumber = flightnumber;
}
//Attributes
private List<DocumentType> docType = new List<DocumentType>();
private string flightNumber;
//helper variables
string docTypeNumber;
string docTypeDescription;
int pageNumber = 1;
int numberOfPages;
private static Font barcodeFont = new Font("3 of 9 Barcode", 24);
private static Font printFont = new Font("Arial", 24);
public void Print()
{
numberOfPages = docType.Count;
PrintDocument pd = new PrintDocument();
foreach (DocumentType type in docType)
{
docTypeNumber = type.DocumentTypeNumber;
docTypeDescription = type.DocumentDescription;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
}//end foreach
#if DEBUG
PrintPreviewDialog printPreview = new PrintPreviewDialog();
printPreview.Document = pd;
printPreview.Show();
#else
pd.Print();
#endif
}// end Print() method
public void pd_PrintPage(Object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
//e.Graphics.PageUnit = GraphicsUnit.Point;
e.Graphics.PageUnit = GraphicsUnit.Inch;
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
Brush br = new SolidBrush(Color.Black);
RectangleF rec1 = new RectangleF(1.9375f, 0f, 4, 1);
RectangleF rec2 = new RectangleF(1.9375f, .5f, 4, 1);
RectangleF rec3 = new RectangleF(1.9375f, 1f, 4, 1);
RectangleF rec4 = new RectangleF(1.9375f, 2, 4, 1);
RectangleF rec5 = new RectangleF(1.9375f, 2.5f, 4, 1);
g.DrawString("Air - " + docTypeDescription, printFont, br, rec1, stringFormat);
g.DrawString("*" + docTypeNumber + "*", barcodeFont, br, rec2, stringFormat);
g.DrawString(docTypeNumber, printFont, br, rec3, stringFormat);
g.DrawString("*" + flightNumber + "*", barcodeFont, br, rec4, stringFormat);
g.DrawString(flightNumber, printFont, br, rec5, stringFormat);
if (pageNumber < numberOfPages)
{
e.HasMorePages = true;
}
else
e.HasMorePages = false;
pageNumber++;
}//end pd_PrintPage Method
}//end BarcodePrinter Class
}//end namespace