简体   繁体   English

跨多页打印 forms

[英]Print forms across multiple pages

I have 3 printing methods: printa, printb, and printc (each printing a form).我有 3 种打印方法:printa、printb 和 printc(每种打印一个表格)。 All the 3 forms need to be printed across multiple pages.所有 3 个 forms 都需要跨多页打印。 How can I print across 3 pages?如何打印 3 页?

I know that we need to use the the event handler and use currentpage and e.hasmorepages but I'm not sure how to use it.我知道我们需要使用事件处理程序并使用 currentpage 和 e.hasmorepages 但我不确定如何使用它。

Simply keep track of the page number.只需跟踪页码。 You set it to 0 in the BeginPrint event and increment it every time that PrintPage is called.您在 BeginPrint 事件中将其设置为 0,并在每次调用 PrintPage 时将其递增。 Like this:像这样:

    int pageNumber;

    private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
        pageNumber = 0;
    }

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) {
        ++pageNumber;
        e.HasMorePages = true;
        switch (pageNumber) {
            case 1: printa(e); break;
            case 2: printb(e); break;
            case 3: printc(e); e.HasMorePages = false; break;
        }
    }

Yeah, it can be pretty obscure.是的,它可能非常模糊。 Here's how I did it for printing Reporting Services reports (the MetaFile image array in the code below).下面是我打印 Reporting Services报告的方法(下面代码中的 MetaFile 图像数组)。

public void Print()
{
    if (emfImage == null || emfImage.Count <= 0)
    {
        throw new ArgumentException("An image is required to print.");
    }

    printer = printer.Trim();
    if (string.IsNullOrEmpty(printer))
    {
        throw new ArgumentException("A printer is required.");
    }

    printingPage = 0;
    PrintDocument pd = new PrintDocument();
    pd.PrinterSettings.PrinterName = printer;
    pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
    pd.Print();
}

private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
    Metafile page = emfImage[printingPage];
    e.Graphics.DrawImage(page, 0, 0, page.Width, page.Height);

    e.HasMorePages = ++printingPage < emfImage.Count;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM