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

Is it possible to combine two PrintDocuments or...

P: n/a
add them into one PrintDocument:
PrintDocument pd1 = new PrintDocument();
PrintDocument pd2 = new PrintDocument();

PrintDocument pdCombined = new PrintDocument();
pdCombined = pd1 + pd2;
pdCombined.Print();
Thanks,
Trint

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


P: n/a
What is your larger problem? You can't do this directly as you
described, but a PrintDocument object doesn't actually contain the
information to print. It relies on some outside object in your
application responding to its PrintPage events and drawing each page as
needed.

Where are your two PrintDocuments pd1 and pd2 coming from? For example,
if they are two input streams from two files, it should be a simple
matter to make a "combined stream" that reads from one and then from
the other, and feed that to your printing class.

In other words, I know of know way to combine two documents into one
after they've been "made into" PrintDocuments, but you should be able
to do it before, and create only one PrintDocument. Of course, that all
depends upon where the actual page rendering is taking place....
So, what are you trying to do, at a higher level?

Nov 16 '05 #2

P: n/a
Bruce,
I am trying to do this:
Set my copies value to 3
start the first copy with a paper source (tray) as 4
when first copy is rendered, set paper source for
second copy to come from paper source 5.
When second copy is rendered, set paper source to come from 6 and that
is all. So that when printer actually begins the printjob it has been
sent, it prints three copies; one copy from each of the selected paper
trays (since we need a white paper copy, a yellow one and a pink one).
Here is my code so far:
class PrintReporttoLaserjet: Form1
{
PrintDocument pd = new PrintDocument();
// PrintReporttoLaserjet NeWrs = new PrintReporttoLaserjet();

// Form1 Form1Form = new Form1();
// Form1Form.ReportingService rs = new ReportingService();
private byte[][] m_renderedReport;
private Graphics.EnumerateMetafileProc m_delegate = null;
private MemoryStream m_currentPageStream;
private Metafile m_metafile = null;
int m_numberOfPages;
private int m_currentPrintingPage;
private int m_lastPrintingPage;

public PrintReporttoLaserjet()
{
// Create proxy object and authenticate
//Console.WriteLine("Authenticating to the Web service...");
rs = new ReportingService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
}

public byte[][] RenderReport(string reportPath)
{
// Private variables for rendering
string deviceInfo = null;
string format = "IMAGE";
Byte[] firstPage = null;
string encoding;
string mimeType;
Warning[] warnings = null;
ParameterValue[] reportHistoryParameters = null;
string[] streamIDs = null;
Byte[][] pages = null;
///mine
// Build device info based on the start page

deviceInfo =
String.Format(@"<DeviceInfo>" +
"<OutputFormat>{0}</OutputFormat>" +
"<Toolbar>False</Toolbar>" +
"<PageHeight>55.82cm</PageHeight>" +
"<PageWidth>40.26cm</PageWidth></DeviceInfo>","emf");

// Prepare report parameter.
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = new ParameterValue();
parameters[0].Name = "InvoiceNumber";
parameters[0].Value = Class1.inVoiceNumber;
//parameters[0].Value = "5440517";
//Exectute the report and get page count.
try
{
// Renders the first page of the report and returns streamIDs for
// subsequent pages
//firstPage = rs.Render(
firstPage = rs.Render(
reportPath,
format,
null,
deviceInfo,
parameters,
null,
null,
out encoding,
out mimeType,
out reportHistoryParameters,
out warnings,
out streamIDs);

// The total number of pages of the report is 1 + the streamIDs
m_numberOfPages = streamIDs.Length + 1;
pages = new Byte[m_numberOfPages][];

// The first page was already rendered
pages[0] = firstPage;

for (int pageIndex = 1; pageIndex < m_numberOfPages; pageIndex++)
{
// Build device info based on start page
deviceInfo =
String.Format(@"<DeviceInfo><OutputFormat>{0}</OutputFormat><Star
tPage>{1}</StartPage></DeviceInfo>","emf", pageIndex+1);

pages[pageIndex] = rs.Render(
reportPath,
format,
null,
deviceInfo,
parameters,
null,
null,
out encoding,
out mimeType,
out reportHistoryParameters,
out warnings,
out streamIDs);
}
}

catch (SoapException ex)
{
//Console.WriteLine(ex.Detail.InnerXml);
using (StreamWriter sw = new StreamWriter("TestFile.txt"))
{
sw.Write(ex.Detail.InnerXml);
}

}
finally
{
//Console.WriteLine("Number of pages: {0}", pages.Length);
}

return pages;
}

public bool PrintReport(string printerName)
{
int PDcounter;

// for (PDcounter = 0; PDcounter <= 2; Class1.counter++)
// {
this.RenderedReport = this.RenderReport(@"/Report
PackingList1/Report1");
//D:\Inetpub\wwwroot\PackingList\Report Project1\printtest
//Report/PackingList1/Report1
PrintReporttoLaserjet f1 = new PrintReporttoLaserjet();

try
{
// Wait for the report to completely render.
if(m_numberOfPages < 1)
return false;
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;

pd.DefaultPageSettings.PaperSource =
pd.PrinterSettings.PaperSources[comboBox1.SelectedIndex = 4];

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

try
{
///Print from tray 2
///Print from tray 3
///Print from tray 4
// Set the paper source based upon the selection in the combo box.
// pd.DefaultPageSettings.PaperSource =
// pd.PrinterSettings.PaperSources[comboBox1.SelectedIndex =
Class1.counter];

int pCounter = 0;
// while (pd.Print())
// {
// pCounter++;
//
// if(printerSettings.Copies == 2)
// {
// pd.DefaultPageSettings.PaperSource =
// pd.PrinterSettings.PaperSources[comboBox1.SelectedIndex = 5];
//
// }
// if(printerSettings.Copies == 1)
// {
// pd.DefaultPageSettings.PaperSource =
// pd.PrinterSettings.PaperSources[comboBox1.SelectedIndex = 6];
//
// }
//
// if(pCounter == 6)
// break;
//
// }
pd.Print();
//Wmis.PStatus();
}
catch(Exception ee)
{
MessageBox.Show(ee.Message);
}
finally
{
// PrintDirect.ClosePrinter(lhPrinter);
}

}

catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
// Clean up goes here.
}
// if(PDcounter == 2)
// break;
// }
return true;
}

private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
ev.HasMorePages = false;
if (m_currentPrintingPage <= m_lastPrintingPage &&
MoveToPage(m_currentPrintingPage))
{
// Draw the page
ReportDrawPage(ev.Graphics);
// If the next page is less than or equal to the last page,
// print another page.
if (++m_currentPrintingPage <= m_lastPrintingPage)
ev.HasMorePages = true;
}
}

// Method to draw the current emf memory stream
private void ReportDrawPage(Graphics g)
{
if(null == m_currentPageStream || 0 == m_currentPageStream.Length ||
null ==m_metafile)
return;
lock(this)
{
// Set the metafile delegate.

int width = m_metafile.Width;
int height= m_metafile.Height;
m_delegate = new Graphics.EnumerateMetafileProc(MetafileCallback);
// Draw in the rectangle

Point[] points = new Point[3];
Point destPoint = new Point(0, 0);
Point destPoint1 = new Point(width, 0);
Point destPoint2 = new Point(0, height);

points[0]=destPoint;
points[1]=destPoint1;
points[2]=destPoint2;
g.EnumerateMetafile(m_metafile,points, m_delegate);

//g.EnumerateMetafile(m_metafile,destPoint , m_delegate);
// Clean up
m_delegate = null;
}
}

private bool MoveToPage(Int32 page)
{
// Check to make sure that the current page exists in
// the array list
if(null == this.RenderedReport[m_currentPrintingPage-1])
return false;
// Set current page stream equal to the rendered page
m_currentPageStream = new
MemoryStream(this.RenderedReport[m_currentPrintingPage-1]);
// Set its postion to start.
m_currentPageStream.Position = 0;
// Initialize the metafile
if(null != m_metafile)
{
m_metafile.Dispose();
m_metafile = null;
}
// Load the metafile image for this page
m_metafile = new Metafile((Stream)m_currentPageStream);
return true;
}

private bool MetafileCallback(
EmfPlusRecordType recordType,
int flags,
int dataSize,
IntPtr data,
PlayRecordCallback callbackData)
{
byte[] dataArray = null;
// Dance around unmanaged code.
if (data != IntPtr.Zero)
{
// Copy the unmanaged record to a managed byte buffer
// that can be used by PlayRecord.
// dataArray = new byte[dataSize];
dataArray = new byte[dataSize];
Marshal.Copy(data, dataArray, 0, dataSize);
}
// play the record.
m_metafile.PlayRecord(recordType, flags, dataSize, dataArray);

return true;
}

public byte[][] RenderedReport
{
get
{
return m_renderedReport;
}
set
{
m_renderedReport = value;
}
}
}

Thanks,
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 #3

P: n/a
So far as I know you can't do it that way.

Each print job (PrintDocument) is an object that specifies where its
paper is being fed from, whether it is using duplex, stuff like that.
One job has one set of attributes.

When you send three copies to a printer, the PC doesn't send the job
three times, or monitor the progress of the job. It sends the job once
and asks the printer to make three copies. (This applies to most modern
/ laser printers. Older printers without sophisticated software may
work differently. Regardless, the drivers are all designed so that your
software neither knows nor cares how the copies are being made.)

If your printer is on a print server then the job may print, and the
copies may be created, long after your application terminates.

One way to do what you want is to create three separate print jobs: one
feeding from paper source 4, one from paper source 5, and one from
paper source 6. Unfortunately, this creates three separate print jobs,
which aren't guaranteed to print in sequence, and won't interleave your
coloured pages, which is probably what you want. (You probably want the
first page white, yellow, pink, then the second page white, yellow,
pink, etc.)

To do the job up nicely, what you need to do is change pd_PrintPage.

First, you need a counter for pd_PrintPage, so that instead of
incrementing m_currentPrintingPage every time, you increment the
counter up to 3, then increment m_currentPrintingPage. So, in effect
calls to pd_PrintPage look like this:

pd_PrintPage: m_currentPrintingPage 1, copy 1
pd_PrintPage: m_currentPrintingPage 1, copy 2
pd_PrintPage: m_currentPrintingPage 1, copy 3
pd_PrintPage: m_currentPrintingPage 2, copy 1
pd_PrintPage: m_currentPrintingPage 2, copy 1
pd_PrintPage: m_currentPrintingPage 2, copy 1
etc.

So, now you have pd_PrintPage being called once for each copy of each
page. (Of course, you can get rid of your setting
printerSettings.Copies = 3, because you're now making the copies
"manually" inside pd_PrintPage.)

Now, you'll notice that pd_PrintPage receives a PrintPageEventAr*gs
class. One of the members of this class is PageSettings, and inside
there you'll find PaperSource. Inside pd_PrintPage just do this:

switch (m_copy)
{
case 1:
ev.PageSettings.PaperSource = ... ;
break;
case 2:
ev.PageSettings.PaperSource = ... ;
break;
case 3:
ev.PageSettings.PaperSource = ... ;
break;
default:
break;
}

Now you set the paper source to a different tray for each copy of each
page.

Nov 16 '05 #4

P: n/a
Bruce,
I will try this immediately and get right back to you...you are very
helpful.
Thanks,
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 #5

P: n/a
Oh, crap. My little example should have read:

pd_PrintPage: m_currentPrintingPage 1, copy 1
pd_PrintPage: m_currentPrintingPage 1, copy 2
pd_PrintPage: m_currentPrintingPage 1, copy 3
pd_PrintPage: m_currentPrintingPage 2, copy 1
pd_PrintPage: m_currentPrintingPage 2, copy 2
pd_PrintPage: m_currentPrintingPage 2, copy 3
etc.

That's what I get for using cut and paste.... :)

Nov 16 '05 #6

P: n/a
Thank you.

Trint, I'm going to give you a nudge as well: you have the same problem
being discussed in several threads here. Rather than posting your
problem over and over again in a new thread each time, please stick to
one thread. It makes things easier for all concerned, and makes it more
likely that you'll get quality responses.

Even if you post your problem and the answers you get back indicate
that nobody understood, reply to the original thread and add more
information, or rephrase the question. That way we can all see the
history and you don't have two different people trying to solve the
same problem without knowing about it, the way we have now.

Most newsreaders show threads in order of the last response to the
thread, most recent first, so if you reply to an old thread most people
will see the entire thread move to the top of their new list. There is
nothing to be gained by starting a new thread, unless, of course, you
have a totally different problem to discuss. :)

Nov 16 '05 #7

P: n/a
By the way, remember to check with the users (if you can) to see what
they're going to do with the copies.

If all they do is immediately separate them and send the white copy
here, and the yellow copy there, and the pink copy over there, then
just do three print jobs, since they don't need to be interleaved.

Can't count the number of times that I've made a Herculean effort to
get something like this to work "just right" only to discover that the
first thing my users do is some manual task that undoes all of my
tricky programming, and that both they and I would have been happer if
I'd just done it the drop-dead easy way. When I tell them that I can do
it the cheap and easy way (although I don't tell them that it's cheap
and easy), the response I often get is, "Oh, that would be fantastic...
you mean you can _do_ that?" :)

Nov 16 '05 #8

P: n/a
Bruce,
I need a copy from tray 1 (white),
tray 2 (yellow),
and tray 3 (pink).
right before the print command I set the papersource to tray 1:
Class1.trayCount = 1;
pd.DefaultPageSettings.PaperSource =
pd.PrinterSettings.PaperSources[comboBox1.SelectedIndex =
Class1.trayCount]; Class1.trayCount = 4;
pd.Print();
I need a place that hits once for every copy...plus, I don't understand
where to put the code you gave me, other than in the:
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
If I can get this one thing today, I will have solved a two week old
problem.
Thanks,
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 #9

P: n/a
OK... you have to remember the following distinction.

The settings you make just before you call pd.Print() are _defaults_
for the _entire print job_. These defaults apply to every page for
which you do not specify explicit settings for _that page_.

However, every call into pd_PrintPage(object sender, PrintPageEventArgs
*ev) gives you the chance to change those settings _for that single
page_ that you're rendering during that call to pd_PrintPage().

In your case, you don't really care about the settings you make before
you call pd_PrintPage. They would come into play only if someone bumped
the number of copies from 3 to 4 and forgot to modify the code in
pd_PrintPage to compensate. Don't worry about that: the point is that
the settings you make before you call pd.Print() don't matter because
you'll be overriding them all anyway inside each call to
pd_PrintPage().

Yes, the code you need to change is inside pd_PrintPage() (other than
getting rid of the Copies=3 that you set before you called pd.Print()).
If you want to attack this problem in bite-sized chunks, do the
following:

1. Get rid of the .Copies=3 before you call pd.Print(). Run your
program. It should produce only one copy.
2. Add a new variable, this.m_copy, an integer. Initialize it to 1 just
before you call pd.Print(). Now, change pd_PrintPage() to do this:

// If this is the last copy then move to the next page
if (this.m_copy < 3)
{
this.m_copy += 1;
}
else
{
this.m_copy = 1;

// If the next page is less than or equal to the last p*age,
// print another page.
if (++m_currentPrintingPage <= m_lastPrintingPage)
ev.HasMorePages = true;
}

Now run your program again. You should get three copies, as before,
collated: the first page three times, the second page three times, the
third page three times, etc.

3. Now the only thing to do is to change the page setting for each copy
so that it feeds froma different paper source. Add the switch statement
I showed you to the beginning of pd_PrintPage:

private void pd_PrintPage(object sender, PrintPageEventAr*gs ev)
{
switch (m_copy)
{
case 1:
ev.PageSettings.PaperSource = ... ;
break;
case 2:
ev.PageSettings.PaperSource = ... ;
break;
case 3:
ev.PageSettings.PaperSource = ... ;
break;
default:
// This case will use the default PaperSource that you set
// before pd.Print(), but of course, this should never
happen....
break;
}
....
}

Into each case, substitute what you want the paper source to be for
that copy.

Run your program again. You should get three copies, one on each colour
paper, collated.

OK, so why does this work?

The PrintDocument doesn't really know how many pages there are to
print, or how pages get printed. It just blindly calls pd_PrintPage
over and over until pd_PrintPage says, "nothing more to print". What
page gets printed when, and how many times, is a problem for
pd_PrintPage to solve.

For example, you had to put special code into pd_PrintPage to handle
the situation in which the user asks to start at, say, page 6.
PrintDocument doesn't know how to do this. It just calls pd_PrintPage
the first time and in effect says, "Hey, you print the first page...
whatever page that is. It's no my problem to find the first page to
print... that's your problem."

Similarly, PrintDocument doesn't know or care whether pd_PrintPage is
going to advance to the next page image on each call. If pd_PrintPage
had a bug in it, it might print the same page over and over and
PrintDocument would just keep calling it forever.

In the same light, PrintDocument doesn't know that our new pd_PrintPage
is going to print the same page three times and then move on to the
next page. It just keeps calling until HasMorePages comes back false.
So, we "trick" it: on the first copy, we print the page and then we
_don't increment the page counter_ but increment the copy counter
instead. Then, next time PrintDocument calls pd_PrintPage, it will
print the _same page again_, but PrintDocument doesn't know that or
care. That's our problem to keep track of that. On the third call, once
again, we'll print the _same page_, but this time, knowing that it's
the third copy (because m_copy is 3), we'll reset m_copy to 1 and bump
the page counter up by _one_.

Then, on the next call, we'll print copy 1 of the _next page_, and on
it goes.

For _every copy of every page_ that pd_PrintPage prints (one copy of
one page on each call), it chooses which paper source _that page_
should print on by using the PrintPageEventArgs.

The PrintPageEventArgs.PageSettings class has all of the settings
copied from those original settings you made before you called
pd.Print(). However, pd_PrintPage can change those settings _for the
single copy of the single page that it's rendering_. The next time it's
called the PageSettings are back to their defaults (as you set them
before calling pd.Print()) again. That's OK, because we override the
PaperSource for each copy of each page anyway.

Make sense?

Nov 16 '05 #10

P: n/a
Oh, drat. There was a coding error in a snippet I gave you. The copy
logic should read like this:

// If this is the last copy then move to the next page
if (this.m_copy < 3)
{
this.m_copy += 1;
ev.HasMorePages = true;
}
else
{
this.m_copy = 1;

// If the next page is less than or equal to the last p*age,
// print another page.
if (++m_currentPrintingPage <= m_lastPrintingPage)
ev.HasMorePages = true;
}

Nov 16 '05 #11

P: n/a
Bruce,
I got some errors that I need you to help me work out, since my level of
experience is not as high as yours.
I got a fallthrough error:
'WindowsApplication1.Form1.PrintReporttoLaserjet' does not contain a
definition for 'm_copy'
on this line:
this.m_copy = this.m_copy(1);
pd.Print();
I got a:
The name 'm_copy' does not exist in the class or namespace
'WindowsApplication1.Form1.PrintReporttoLaserjet'
on this line:
switch (m_copy)
I got a:
Control cannot fall through from one case label ('default:') to another
on this line:
switch (m_copy)
and this error:
'WindowsApplication1.Form1.PrintReporttoLaserjet' does not contain a
definition for 'm_copy'
on each of these lines:
if (m_currentPrintingPage <= m_lastPrintingPage &&
MoveToPage(m_currentPrintingPage))
{
// Draw the page
ReportDrawPage(ev.Graphics);
// If this is the last copy then move to the next page
if (this.m_copy < 3)
{
this.m_copy += 1;
}
else
{
this.m_copy = 1;
}

If you can get me going with this, it is much appreciated...
One more thing:
When all three of these invoice copies defalt print to OutPutBin1 (which
is where they now go), they are automatically stapled by this printer.
Also, this printer is dedicated to only doing this one thing, so I don't
have to worry about the other people ever printing to it.
thanks,
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 #12

P: n/a
Trint,

In point #2, when I said that you had to declare a new variable,
m_copy, an int, I meant that you had to make it a class member. At the
start of your class:

public class PrintReporttoLaserjet
{
private int m_copy;
....
}

That should solve most of your errors, if not all of them.

The error about not being able to fall through from one case to the
next, in the "switch" statement, is either a red herring, or you forgot
one of the "break" statements. Every case, including the default:,
needs a "break" just before the next case. The "default" case should
consist of one line: "break;" (apart from the comment I put there).

You did get my note about the if (this.m_copy < 3)... missing a line,
didn't you?

Nov 16 '05 #13

P: n/a
Bruce,
Thanks again for your help...I have one error left after changing the
private int m_copy; and the ev.PrinterSettings to pd.PrinterSettings.
Here is the error:
error CS0163: Control cannot fall through from one case label
('default:') to another
On this line:
switch (m_copy).
Thanks.
Bruce, I may have a problem that will change everything that we have
discussed...the third page (the pink one) must NOT have the prices
showing in it (this according to my IT Director). Plus, I may have to
leave the "pd_PrintPage" as it originally was because it is already
handling the "if the emf memory stream document (the invoice) has
multiple pages (not copies). Since that is the case, I may have to
revert to my original question "Is it possible to combine multiple
documents and send them as one printdocument to the laserjet 4350tn"?
The reason is:
When I get an object handle (like "pd., pd2. and pd3.") for all three of
these documents, they must all go out as one printjob or one document
because if the laserjet senses that printdocument.print has been called
on only one page at a time, it automatically drops one page at a time in
another output bin instead of the "stapler stacker" bin so that all
three copies of the invoice (and the last page will be a separate report
because, eventhough identical to the first two except it has NO prices
on it) can be stapled.
Sooo, here is the REAL question:
Is it possible for me to collect all three documents (pd., pd2. and
pd3.) and combine them into one printdocument before calling
"pd.Print();" which will really be comBinedpd's.print somehow?
Here is someones idea on that:
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++;
}
}
If care to help with this [more complex] issue, I REALLY appreciate it.
Thanks,
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 #14

P: n/a
Trint,

Please copy your entire (new) pd_PrintPage() method here so that I can
see it. The error you are getting indicates that you are missing a
"break" statement in your "switch" somewhere. I need to see the whole
method in order to find the problem.
Plus, I m*ay have to
leave the "pd_PrintPage" as it originally was because it is *already handling the "if the emf memory stream document (the invoice*) has
multiple pages (not copies).


If you followed my instructions carefully, you will find that the new
pd_PrintPage handles multiple copies and multiple pages correctly. Read
my posts again: remember that I said that pd_PrintPage would be called
for:

pd_PrintPage: m_currentPrintingPage 1, copy 1
pd_PrintPage: m_currentPrintingPage 1, copy 2
pd_PrintPage: m_currentPrintingPage 1, copy 3
pd_PrintPage: m_currentPrintingPage 2, copy 1
pd_PrintPage: m_currentPrintingPage 2, copy 2
pd_PrintPage: m_currentPrintingPage 2, copy 3
etc.

If someone is telling you that this new design will print only three
copies for a single invoice, and not print the other pages, then they
are quite simply mistaken. If you want the pages to print in a
different order, then that can be arranged, too.

It is not possible to combine multiple PrintDocuments into one print
job. Can't be done. However, take heart. pd_PrintPage can once again be
adjusted to print multiple documents, each with multiple pages, in
multiple copies. You just need to decide upon the order in which you
want things printed. That is, do you want printing by the document,
then by the page, then by the copy:

Document 1, page 1, copy 1
Document 1, page 1, copy 2
Document 1, page 1, copy 3
Document 1, page 2, copy 1
Document 1, page 2, copy 2
Document 1, page 2, copy 3
Document 2, page 1, copy 1
Document 2, page 1, copy 2
Document 2, page 1, copy 3
etc.

or do you want printing by the document, by the copy, then by the page?

Document 1, page 1, copy 1
Document 1, page 2, copy 1
Document 1, page 1, copy 2
Document 1, page 2, copy 2
Document 1, page 1, copy 3
Document 1, page 1, copy 3
Document 2, page 1, copy 1
Document 2, page 1, copy 2
Document 2, page 1, copy 3
etc.

In other words, for each document, do you want the first page white,
then yellow, then pink, then the next page white, then yellow, then
pink, or do you want the entire document (all pages) printed on white
paper, then the entire document again on yellow paper, then the entire
document again on pink paper, then start the next document?

Finally, as for the pink copy not having the price on it, I will have
to find the post where you posted your code again, but that should be a
relatively easy adjustment. I will post a suggestion shortly.

Nov 16 '05 #15

P: n/a
Trint,

I have a question about your reporting system. Your boss says that the
last page (the pink copy) cannot have the prices on it. How would you
print a whole new report without the prices? In the code you posted
there are lots of calls to objects and methods that are obviously
peculiar to your system. How would you make a call to generate a report
without the prices?

I'm guessing that you would do something different in RenderReport, but
what? Would you pass it a different reportPath to print in a different
format? I need to know this before I can advise you on how to modify
your class in order to print the third copy differently.

Again, I want to impress a couple of things on you:

1. There is no need to undo all of the work you've done over the past
while. You are proceeding in the correct direction to achieve all of
the project's goals. In fact, you are proceeding in the only direction
that will achieve all of your objectives.

2. Proceed step by step. I notice that you didn't do this the last time
when I told you to. :) Get the application working, printing three
copies, even if it's not the page order you want, or the pink copy
still shows the prices. Then, when you have that, make a change, and
test it again. _DO NOT_ attempt to throw all of the changes in at once
and run it with your fingers crossed, hoping that it will miraculously
work. It will not, and that will cost you valuable time and frustrate
you, as I think you've already discovered. I've been doing this for 20
years. Trust me. :)

Nov 16 '05 #16

P: n/a
Bruce, you are right...:) I am working on what you have suggested...I
have to redo my project for the reports first so that they actually
show...in about 40 minutes, I should have this all set...your question:
"How would you print a whole new report without the prices?"

here:
public bool PrintReport3(string printerName)
{
this.RenderedReport = this.RenderReport(@"/Report
PackingList1/Report2");

This function has to be called last to render the 2nd report (which is
the 3rd "copy")...the 1st and second pages are really just one report
"(@"/Report PackingList1/Report1");"
I'm really trusting you to get me out of this hole...
Thanks,
Trint

Bruce Wood wrote:
Trint,

I have a question about your reporting system. Your boss says that the last page (the pink copy) cannot have the prices on it. How would you
print a whole new report without the prices? In the code you posted
there are lots of calls to objects and methods that are obviously
peculiar to your system. How would you make a call to generate a report without the prices?

I'm guessing that you would do something different in RenderReport, but what? Would you pass it a different reportPath to print in a different format? I need to know this before I can advise you on how to modify
your class in order to print the third copy differently.

Again, I want to impress a couple of things on you:

1. There is no need to undo all of the work you've done over the past
while. You are proceeding in the correct direction to achieve all of
the project's goals. In fact, you are proceeding in the only direction that will achieve all of your objectives.

2. Proceed step by step. I notice that you didn't do this the last time when I told you to. :) Get the application working, printing three
copies, even if it's not the page order you want, or the pink copy
still shows the prices. Then, when you have that, make a change, and
test it again. _DO NOT_ attempt to throw all of the changes in at once and run it with your fingers crossed, hoping that it will miraculously work. It will not, and that will cost you valuable time and frustrate
you, as I think you've already discovered. I've been doing this for 20 years. Trust me. :)


Nov 16 '05 #17

P: n/a
One thing I don't understand is how do I write this?:
Document 1, page 1, copy 1
Document 1, page 1, copy 2
Document 1, page 1, copy 3
Document 1, page 2, copy 1
Document 1, page 2, copy 2
Document 1, page 2, copy 3
Document 2, page 1, copy 1
Document 2, page 1, copy 2
Document 2, page 1, copy 3
Thanks,
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 #18

P: n/a
OK,
I got it exactly as you have said...I fixed the error by puting it this
way:

try
{
///Print from tray 2
///Print from tray 3
///Print from tray 4
// Set the paper source based upon the selection in the combo
box.
// pd.DefaultPageSettings.PaperSource =
// pd.PrinterSettings.PaperSources[comboBox1.SelectedIndex =
Class1.counter];

this.m_copy = 1;
Class1.pd.Print();

private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
switch (m_copy)
{
case 1:
//ev.PageSettings.PaperSource = ... ;
ev.PageSettings.PaperSource =
Class1.pd.PrinterSettings.PaperSources[comboBox1.SelectedIndex =
4];
break;
case 2:
//ev.PageSettings.PaperSource = ... ;
ev.PageSettings.PaperSource =
Class1.pd.PrinterSettings.PaperSources[comboBox1.SelectedIndex =
5];
break;
case 3:
//ev.PageSettings.PaperSource = ... ;
ev.PageSettings.PaperSource =
Class1.pd.PrinterSettings.PaperSources[comboBox1.SelectedIndex =
6];
break;
default:
break;
}
ev.HasMorePages = false;
if (m_currentPrintingPage <= m_lastPrintingPage &&
MoveToPage(m_currentPrintingPage))
{
// Draw the page
ReportDrawPage(ev.Graphics);
// If this is the last copy then move to the next page
if (this.m_copy < 3)
{
this.m_copy += 1;
ev.HasMorePages = true;
}
else
{
this.m_copy = 1;
}
// If the next page is less than or equal to the last page,
// print another page.
if (++m_currentPrintingPage <= m_lastPrintingPage)
ev.HasMorePages = true;
}
}
But it prints one page from tray 4 which is index 6, and draws a second
page from tray 2 index 4.
Thanks,
Trint

Nov 16 '05 #19

P: n/a
Trint,

You have an error in the last part of the pd_PrintPage function. It
should read like this:

if (this.m_copy < 3)
{
this.m_copy += 1
;
ev.HasMorePages = true;

}
else
{
this.m_copy = 1;
// If the next page is
less than or equal to the last p*age,
// print another page.
if
(++m_currentPrintingPage <= m_lastPrintingPage)
ev.HasMorePages
= true;
}

.... the "if (++m_currentPrintingPage <= m_lastPrintingPage)" test and
the following "ev.HasMorePages = true;" should be _inside_ the "else"
part of the "if (this.m_copy < 3)" test, not outside it.

Your problem with the paper trays may be due to what you're doing with
comboBox1.SelectedIndex = 4, etc. What are you trying to do there?
Shouldn't there be three combo boxes, so the user can select a paper
source for each of the three copies, or are you trying to do something
else?

Please let me know what the business requirement is behind the combo
boxes. I definitely don't understand.

You're getting close.

I've worked out how to make copy 3 different from the other two. Once
you get this working I'll let you know what you need to change for
that.

Your final requirement, I think, was that you have several of these
invoices (several "reports") to print together in one print job,
whereas right now what you have prints only one, but in three copies,
etc. as we've discussed.

What I'm missing is how you feed the report data into RenderReport. Is
that part of this RenderReport(@"Report PackingList1/Report2") thing?
Is "Report2" the _format_, while "PackingList1" the _data_, or am I
confused?

Asked another way, if you render the first invoice in its two different
formats (one with prices, one without) like this:

RenderReport(@"Report PackingList1/Report1");
RenderReport(@"Report PackingList1/Report2");

Then how do you render the second invoice? Is it like this?

RenderReport(@"Report PackingList2/Report1");
RenderReport(@"Report PackingList2/Report2");

If I "don't get it"... please fill me in.

Nov 16 '05 #20

P: n/a
Trint,

A couple of other notes.

First, you do realize that you don't need the static variable Class1.pd
in order to get your hands on the paper sources for the printer from
within pd_PrintPage. You can get that this through the
PrintPageEventArgs, like this:

ev.PageSettings.PaperSource =
ev.PageSettings.PrinterSettings.PaperSources[...];

Second, I just want to clarify my previous note about the combo box. I
understand what you're trying to do in selecting different paper
sources (I think that you see that it's working, just not the way that
you want). I just don't understand why you're involving a combo box. It
looks to me as though

ev.PageSettings.PaperSource =
ev.PageSettings.PrinterSettings.PaperSources[comboBox1.SelectedIndex =
4];

is exactly the same as

ev.PageSettings.PaperSource =
ev.PageSettings.PrinterSettings.PaperSources[4];

I don't understand why you're involving the combo box at all. I think
that I need to know what was the business requirement behind the combo
box thing... what was the original idea that led you to use a combo box.

Nov 16 '05 #21

P: n/a
Ok,
It is working...is exactly as you have said...thank you. But, it is
printing in this order for some reason??:
tray 4
tray 2
tray 3
You were also right about the indexing number of the devices...I got
that from the explanation MS gave on papersourcekind...they said that I
have to do a retrieve of the devices index first...
Anyway...
the second report:
These reports I did like Crystal Reports, but with MS SQL Server 2000
Reporting Services.
they are located in those paths...the real names of the reports are
Report1.rdl (the one with the prices) and Report2.rdl (the one without
the prices).
I haven't figured out how to render the Report2.rdl yet anyway...I
mean, I can create a second PrintReport function that will render the
2nd report, but now that we have this, I don't know...at least we are
pull from three separate trays now...
Good question...How can I render the second report before
PrintPageEventArgs release to print the job?
Another thing, you probably already know...this rendering Must be done
as an enhanced meta-file or "emf" since MS says, that is the only
format that rs.render can determine how many pages a report is. You
have no idea how you are helping me.
You are a Good Programmer.
Thanks for your help.
Trint

Nov 16 '05 #22

P: n/a
You mean more than one document? Patience. One thing at a time. Let's
get the multiple copies working first. :)

Trint... I'm thinking that we should take this conversation out of the
newsgroup and into e-mail. It would be quicker and wouldn't annoy all
of these other people with our chatting back and forth about your
specific problem.

Any objections?

Nov 16 '05 #23

P: n/a
That is great, my email is:

tr***********@gmail.com

The construction guys are making all of IT leave until in the
morning...
Before I go out the door, do you think it is possible to (without me
jumping ahead) render the second report and add it to the printjob as
the same document?
How do you know these undocumentd features anyway?
Thanks,
Trint

Nov 16 '05 #24

P: n/a
The second report? You mean another invoice number, or the third copy
without prices?

If you want to finish up one thing today before you go, let's get the
e-mail conversation started. I'll send you an e-mail right now. If you
get it, you can reply and we can carry on the conversation that way.
Much better, I think.

Nov 16 '05 #25

This discussion thread is closed

Replies have been disabled for this discussion.