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

how to create and print multi page document

P: 11
Had no luck in the visual basic group maybe someone here can give me a hand.

I have been tring to recreate a simple program that I wrote many years ago in quick basic. The program get name and address from a database, then the user will enter in info like order #, po # and starting box then number of boxes.

In quick basic it was easy to send a form feed and print the next label. But this visual basic .net stuff has me pulling my hair out. I can print all the info to desired printer. But do not understand how to created a multi page document to send. I could have it loop through all the box numbers and call the print routine multiply time but This would send many seperate print jobs.
I will paste code below (it's not pretty) I'll start with the print button code and then jump to the class it is calling to.

Hope someone can make sense of this and maybe even help me,
David DeWitt

/CODE/

Public Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click

Dim Print As New myPrinter
Call Print.prt()

End Sub


Public Class myPrinter


Public Sub prt()

Dim prn As New Drawing.Printing.PrintDocument
Using (prn)
prn.PrinterSettings.PrinterName = My.Settings.Printer
AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
prn.Print()
RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
End Using
End Sub

Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As Drawing.Printing.PrintPageEventArgs)
Dim smFont As New Font("Microsoft San Serif", 10)
Dim medFont As New Font("Microsoft San Serif", 14)
Dim lrgFont As New Font("Microsoft San Serif", 18)
Dim startlbl As Integer = MainForm.txtStartBoxNUmber.Text
Dim endlbl As Integer = MainForm.txtStartBoxNUmber.Text + MainForm.txtBoxes.Text

Do Until startlbl = endlbl

' return address
args.Graphics.DrawImage(My.Resources.LOGO_2, 60, 10)
args.Graphics.DrawString(My.Settings.returnAddress , New Font(smFont, FontStyle.Regular), Brushes.Black, 117, 70)
args.Graphics.DrawString(My.Settings.returnCity, New Font(smFont, FontStyle.Regular), Brushes.Black, 110, 85)
' ship to address
args.Graphics.DrawString("Ship to:", New Font(medFont, FontStyle.Bold), Brushes.Black, 5, 150)
args.Graphics.DrawString(MainForm.txtCompanyName.T ext, New Font(lrgFont, FontStyle.Bold), Brushes.Black, 30, 175)
args.Graphics.DrawString(MainForm.txtAttn.Text, New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 210)
args.Graphics.DrawString(MainForm.txtAddress1.Text , New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 235)
args.Graphics.DrawString(MainForm.txtAddress2.Text , New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 260)
args.Graphics.DrawString(MainForm.txtCity.Text & ", " & MainForm.txtState.Text & " " & MainForm.txtZip.Text, New Font(medFont, FontStyle.Regular), Brushes.Black, 30, 285)
' Package & Order information
args.Graphics.DrawString("P.O. #" & MainForm.txtPO.Text, New Font(smFont, FontStyle.Bold), Brushes.Black, 30, 370)
args.Graphics.DrawString("Order #" & MainForm.txtOrderNumber.Text, New Font(smFont, FontStyle.Bold), Brushes.Black, 30, 390)
args.Graphics.DrawString("Box #" & startlbl, New Font(smFont, FontStyle.Bold), Brushes.Black, 30, 410)
startlbl = startlbl + 1
args.HasMorePages = True

Loop
args.HasMorePages = False

End Sub
End Class

/CODE/
Dec 12 '06 #1
Share this Question
Share on Google+
4 Replies


kenobewan
Expert 2.5K+
P: 4,871
Hi David,

I believe we need to rephrase your question to make progress. My understanding is that you want an application with a database, form and output page from which you can print all of the records. Is this correct?

BTW - "[code]" not "/code/" works.
Dec 12 '06 #2

P: 11
Hi David,

I believe we need to rephrase your question to make progress. My understanding is that you want an application with a database, form and output page from which you can print all of the records. Is this correct?

BTW - "[code]" not "/code/" works.

First to briefly descibe program. shipping label program. The user will enter a customer ID number, which pulls up there address in several textboxes, then the user will enter the first box number (defaults to "1") and the number of boxes. Press print and hopefully labels will print. I am able to have the program send all the labels with correct box number, but each label is sent as a seperate print job. I would like to be able to send all the labels as a single print job.

Thanks,
David
Dec 13 '06 #3

kenobewan
Expert 2.5K+
P: 4,871
What I believe is happening is that you are creating a print queue by calling the print event after each loop by using it in the print event handler.

Try coding out the two subs, for testing purposes, and placing all the relevant code in the click event and then ensuring that print is only called after the loop has finished. Once this works you will be able to separate your code as required.

Hope that this helps.
Dec 13 '06 #4

P: 11
What I believe is happening is that you are creating a print queue by calling the print event after each loop by using it in the print event handler.

Try coding out the two subs, for testing purposes, and placing all the relevant code in the click event and then ensuring that print is only called after the loop has finished. Once this works you will be able to separate your code as required.

Hope that this helps.

But how do I tell it to start the next page.

Thanks
Dec 15 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.