How can I send multiple documents to print (As a printjob)?



Instead of just sending one document at a time, I need to send multiple
documents as a print job because our laserprinter will only stack and
staple one printjob it receives at a time.
I need to use some of this code:
PrinterSettings printerSettings = new PrinterSettings();
printerSettings.MaximumPage = m_numberOfPages;
printerSettings.MinimumPage = 1;
printerSettings.PrintRange = PrintRange.SomePages;
printerSettings.FromPage = 1;
printerSettings.ToPage = m_numberOfPages;
printerSettings.Copies = 3;
printerSettings.PrinterName = printerName;

PrintDocument pd = new PrintDocument();
m_currentPrintingPage = 1;
m_lastPrintingPage = m_numberOfPages;
pd.PrinterSettings = printerSettings;
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);

Bruce Johnson

Unless I'm mistaken, you need to combine the documents into a single
PrintDocument. In the .NET Framework, PrintDocument represents a single
document, or a single print job. Because you are using the PrintPage
event, it should be straight forward to keep the HasMorePages property
set to true until you have rendered all of the actual documents that you
want to combine in to a single PrintDocument.

Bruce Johnson [.NET MVP]


No, HasMorePage­s is just for printing the second or so-on pages of
the first document to print (if it goes beyond one page). For example:
a multi-page Invoice...ok, I want 3 invoices (some with multiple pages,
which is already being handled by HasMorePage­s) to be sent to the
printer as a printjob. Instead, I'm only sending one document, and it
may have multiple pages, to the printer with:

Bruce Johnson

What I'm suggesting is that you create a state machine within your
PrintPage event handler. Say you have three separate documents being
generated out of three instances of the same class. At the module
level, keep track of the current document instance. Then within the
PrintPage event simply invoke the PrintPage method for the current
document instance. Something like the following.

DocumentToPrint[] docs = new DocumentToPrint[3];
int currentDoc = 0;

private void PrintPage(Object sender, PrintPageEventArgs e)
docs[currentDoc].PrintPage(sender, e)
if (!e.HasMorePages && currentDoc < docs.Length)
e.HasMorePages = true;

Bruce Johnson [.NET MVP]

Trint Smith

I am trying to use this info you gave me yesterday so that I can finish
up on this project...however, I'm not sure how to declair this in a
class and if it will really print all of my documents as one job.
Please look:

public static DocumentToPrint[] docs = new DocumentToPrint[3];

I get this error at compile:
error CS0246: The type or namespace name 'DocumentToPrint' could not be
found (are you missing a using directive or an assembly reference?)

How will I print these documents? Can I do this?

pe.PrintReport(@"\\WEB1\Shipping1"); <<this sets up the first report.
docs[currentDoc] = printerSettings;[currentDoc].Print();

pe.PrintReport2(@"\\WEB1\Shipping1"); <<this sets up the second report.
docs[currentDoc] = printerSettings;[currentDoc].Print();

pe.PrintReport3(@"\\WEB1\Shipping1"); <<this sets up the third report.
docs[currentDoc] = printerSettings;[currentDoc].Print();

///and how do send these all to the printer at one time?
///like this?:[currentDoc].Print();

Thanks for any help,

.Net programmer
(e-mail address removed)

Bruce Johnson

I can't tell for sure, because I don't know what the pe object or the
PrintReportn methods do. In the code that I provided, the
'DocumentToPrint' class was a dummy one that would have include the
method that supported the PrintPage event handler.

From what it appears, you have created three separate PrintReport
methods, each of which take a path as a parameter. Inside each of these
methods, I assume that you are using the PrintDocument class to do the
printing. If so, where is/are the methods that support the PrintPage

Bruce Johnson [.NET MVP]

Bruce Wood


I'm helping Trint out on a completely different thread with what I
think is the same problem in the same program. (Correct me if I'm
wrong, Trint.) If you want to get into the fray, you can find the
other thread here.

If we keep it all together in one place we can probably produce a
solution more quickly. (Or make a bigger mess... one or the other. :)


You're correct. I just followed the other thread and it sounds like you got
much deeper into the problem than I have to this point. With a solution that
is grounded in the same place, the PrintPage method. Wonderfully patient,
you are. And feel free to keep going with the thread. I'll keep an eye out
and kick in if I have anything useful to contribute.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question