Printing multiple pages of different data

In my application, I have several forms that print specific data. For this, I use the PrintDocument PrintPage Event.

If one report has more than 1 page, I set the hasMorePages flag to true, and the event fires again, and my responsibility is to continue printing from where I was at the end of the last page.

Now I need to print all these reports in ONE PrintDocument, and I want to reuse the code of each of them, so that in one print button the user will receive all the reports printed. The idea is not to print multiple documents.

What will be your approach to this?

+3
source share
1 answer

, , . , , . ​​

, , IPrintableForm, DoPrintEvent (object sender, PrintPageEventArgs args);

, , - :

private multiDocPageEventHandler(object sender, PrintPageEventArgs args)
{
    if (printStack == null) { // all done
        throw new Exception("This should never happen.");
    }
    else { // send to top of stack
        printStack.Peek().DoPrintEvent(sender, args);
        if (!args.HasMorePages) {
             printStack.Pop();
        }
        args.HasMorePages = printStack.Count > 0;
        if (!args.HasMorePages) {
            printStack = null;
        }
    }
}
+2

All Articles