how to create and print multi page document

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DeWittds
    New Member
    • Oct 2006
    • 11

    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.EventArg s) Handles btnPrint.Click

    Dim Print As New myPrinter
    Call Print.prt()

    End Sub


    Public Class myPrinter


    Public Sub prt()

    Dim prn As New Drawing.Printin g.PrintDocument
    Using (prn)
    prn.PrinterSett ings.PrinterNam e = My.Settings.Pri nter
    AddHandler prn.PrintPage, AddressOf Me.PrintPageHan dler
    prn.Print()
    RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHan dler
    End Using
    End Sub

    Private Sub PrintPageHandle r(ByVal sender As Object, ByVal args As Drawing.Printin g.PrintPageEven tArgs)
    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.txtSta rtBoxNUmber.Tex t
    Dim endlbl As Integer = MainForm.txtSta rtBoxNUmber.Tex t + MainForm.txtBox es.Text

    Do Until startlbl = endlbl

    ' return address
    args.Graphics.D rawImage(My.Res ources.LOGO_2, 60, 10)
    args.Graphics.D rawString(My.Se ttings.returnAd dress , New Font(smFont, FontStyle.Regul ar), Brushes.Black, 117, 70)
    args.Graphics.D rawString(My.Se ttings.returnCi ty, New Font(smFont, FontStyle.Regul ar), Brushes.Black, 110, 85)
    ' ship to address
    args.Graphics.D rawString("Ship to:", New Font(medFont, FontStyle.Bold) , Brushes.Black, 5, 150)
    args.Graphics.D rawString(MainF orm.txtCompanyN ame.T ext, New Font(lrgFont, FontStyle.Bold) , Brushes.Black, 30, 175)
    args.Graphics.D rawString(MainF orm.txtAttn.Tex t, New Font(medFont, FontStyle.Regul ar), Brushes.Black, 30, 210)
    args.Graphics.D rawString(MainF orm.txtAddress1 .Text , New Font(medFont, FontStyle.Regul ar), Brushes.Black, 30, 235)
    args.Graphics.D rawString(MainF orm.txtAddress2 .Text , New Font(medFont, FontStyle.Regul ar), Brushes.Black, 30, 260)
    args.Graphics.D rawString(MainF orm.txtCity.Tex t & ", " & MainForm.txtSta te.Text & " " & MainForm.txtZip .Text, New Font(medFont, FontStyle.Regul ar), Brushes.Black, 30, 285)
    ' Package & Order information
    args.Graphics.D rawString("P.O. #" & MainForm.txtPO. Text, New Font(smFont, FontStyle.Bold) , Brushes.Black, 30, 370)
    args.Graphics.D rawString("Orde r #" & MainForm.txtOrd erNumber.Text, New Font(smFont, FontStyle.Bold) , Brushes.Black, 30, 390)
    args.Graphics.D rawString("Box #" & startlbl, New Font(smFont, FontStyle.Bold) , Brushes.Black, 30, 410)
    startlbl = startlbl + 1
    args.HasMorePag es = True

    Loop
    args.HasMorePag es = False

    End Sub
    End Class

    /CODE/
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #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.

    Comment

    • DeWittds
      New Member
      • Oct 2006
      • 11

      #3
      Originally posted by kenobewan
      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

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #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.

        Comment

        • DeWittds
          New Member
          • Oct 2006
          • 11

          #5
          Originally posted by kenobewan
          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

          Comment

          Working...