By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

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

P: n/a
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);
pd.Print();
Thanks,
Trint

Nov 16 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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]
http://www.objectsharp.com/blogs/bruce

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #2

P: n/a
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]
http://www.objectsharp.com/blogs/bruce

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

P: n/a
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:
pd.Print();
Thanks,
Trint

Nov 16 '05 #4

P: n/a
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:
pd.Print();
Thanks,
Trint

Nov 16 '05 #5

P: n/a
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;
currentDoc++;
}
}

Bruce Johnson [.NET MVP]
http://www.objectsharp.com/blogs/bruce

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6

P: n/a
Bruce,
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;
Class1.docs[currentDoc].Print();
Class1.currentDoc++;

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

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

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

Thanks for any help,
Trint

.Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #7

P: n/a
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
event?

Bruce Johnson [.NET MVP]
http://www.objectsharp.com/blogs/bruce

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #8

P: n/a
Bruce,

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. :)

Nov 16 '05 #9

P: n/a
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.

"Bruce Wood" wrote:
Bruce,

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. :)

Nov 16 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.