help with print routine -multiple pages - multiple printers

otonomi

Member
Joined
Mar 15, 2010
Messages
5
Programming Experience
1-3
Hi all,

i need help with my print routine:

I have a routine, with the printDoc_PrintPage() function where i loop my pages and print them on the default printer.

What i need to do is print page 1 on a special printer and the other pages on the default printer.
Does anyone has any ideas how to do this?

I tried with printDoc_QueryPageSettings because this gets triggered before every Printpage() event but i can't get it working.

Help would be appreciated!!

thx
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
1. Split the printDoc into two different documents eg PrintDoc1 and PrintDoc2. Allocate PrintDoc1 and PrintDoc2 to different printers.

2. Define a variable to be set depending on which PrintDoc1/PrintDoc2 is being printed.

3. Change the PrintDoc_PrintPage event to be "handles PrintDoc1.PrintPage, PrintDoc2.PrintPage". Within the PrintPage event, based on the variable value, only do page 1 for PrintDoc1 and do not do page 1 for PrintDoc2.
 

otonomi

Member
Joined
Mar 15, 2010
Messages
5
Programming Experience
1-3
hi, thx for your answer.

i don't quit understand step 3. How can i set PrintDoc1 for page 1 and PrintDoc2 for the other pages?

thx
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
Hand written psuedo code :-

VB.NET:
Private WhatPagesToPrint as string = ""

Private Sub PrintDoc1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDoc1.BeginPrint
    WhatPagesToPrint = "Page 1"
End Sub

Private Sub PrintDoc2_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDoc2.BeginPrint
    WhatPagesToPrint = "All other pages"
End Sub


Private Sub Combined_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDoc1.PrintPage, PrintDoc2.PrintPage
    With e.Graphics
        Select Case WhatPagesToPrint
            Case "Page 1"
                'only do page 1
            Case "All other pages"
                'do NOT do page 1, but do all other pages
        End Select
    End With
End Sub
 

otonomi

Member
Joined
Mar 15, 2010
Messages
5
Programming Experience
1-3
Thx for the code above...

But i can't get it running.

When i call the print routine: Combined.Print(), i need to add Combined.printPage like this:
Private Sub Combined_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDoc1.PrintPage, PrintDoc2.PrintPage, Combined.PrintPage

but then, when i go to the select case WhatPagesToPrint, the value is empty when i debug it...
how is this possible? this is killing me!
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
Without seeing all the code, we can only guess :D
 

otonomi

Member
Joined
Mar 15, 2010
Messages
5
Programming Experience
1-3
this is my code for the functions...
basically in the print routine i loop the pages

if pagenumber is 1 it prints contents, for page 2, it prints other contents and print page 3 or more prints the rest.
 

Attachments

Last edited by a moderator:

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
Normally, I would say - please use CODE tags, as it makes your code easier to read. Unfortunately, in this case, I'm not sure it's going to help much :eek:

The vast majority of your PrintPage code should be put into the BeginPrint subroutine (or earlier). All your queries should be parameterised. Most of your queries are pulling all the fields from the table, yet you are only using a single value - why havent you used ExecuteScalar instead?

To answer your question, when you call Combined.Print(), you havent set the value of sWhatPagesToPrint.

I also think you missed my main point. PrintDoc1 would print page 1, PrintDoc2 would print all other pages. You can then target PrintDoc1 to printer A, and PrintDoc2 to printer B. If you want to print a 'combined' document, send PrintDoc1 and PrintDoc2 to the same printer.
 

otonomi

Member
Joined
Mar 15, 2010
Messages
5
Programming Experience
1-3
ok, now i'm trying to printdoc1 and printdoc2 using the combined document, and it works!
i guess for my printpreview, i need to work with 2 previews since i'm printing on 2 different printers?

thx for your help so far!!! you are the man
 
Top Bottom