Thursday, February 15, 2007

How to print multiple copies of page if PrinterSettings.MaximumCopies==1

I've encountered problem that with all my printers I cannot print several copies of pages using PrinterSettings.Copies=2. .NET Framework just ignore it, and MSDN state why:

You can use the MaximumCopies property to determine the maximum number of copies the printer supports. If the number of copies is set higher than the maximum copies supported by the printer, it will be ignored, not causing an exception.
The problem is that I've never seen the case when MaximumCopies is different than 1. Since this is just a wrapper around GDI DeviceCapabilities(DC_COPIES), I've tried to access it manually via PInvoke, and still get 1
Ok, so how to print multiple copies of the page on the printer, that does not support it? Quite simple:
PrintDocument doc = new PrintDocument();
int remainingPages = /* Number of copies */;
doc.PrintPage += delegate(object sender, PrintPageEventArgs e) {
e.Graphics.DrawImage(/* Print your page here*/);
e.HasMorePages = (--remainingPages > 0);

1 comment:

Anonymous said...

Please, do you know how to obtain the desired number of copies from the print dialog when maximumCopies==1?

I'm always obtaining 1!