473,378 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how to create and print multi page document

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
4 2470
kenobewan
4,871 Expert 4TB
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
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
4,871 Expert 4TB
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
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

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

Similar topics

9
by: trint | last post by:
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...
2
by: Tigger | last post by:
Dear Experts, I've got a trouble problem that I need your help. The scenario is the following: 1) I need to add a "Print" button to my web page; 2) by clicking this button, the web page should...
3
by: Bob | last post by:
I need to create a program that is essentially a special fax sender using multi line Dialogic cards. I figure that the best way to do this so that it can be used from any app is to create someting...
1
by: DeWittds | last post by:
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...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
2
by: =?Utf-8?B?RGlmZmlkZW50?= | last post by:
Hello All, I am trying to offer "Print" functionality using an HTML button with the help of "window.print()" This button works fine in Firefox but not in IE7. I am dumping the entire content...
1
by: Mo | last post by:
Hi, I have two tiff images which present the front and back of a card. I need to send these to images to a printer that has a two sided printing capabilities. I need to send these two images to...
10
by: SM | last post by:
Hello I'm trying to create a multi dimensional array in JavaScript, but after some reading i still can't figure out how to apply it to my model. Here it is: I have a list A and for each item...
0
by: 5anelli | last post by:
Hi to everyone, I need to create and print (from within a c# application) a MS Word document starting from an Access db. Half of this document must be written and printed in, let's say, January,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.