Print on Receipt printer in VB.NET 
Author Message
 Print on Receipt printer in VB.NET

Hello,

I have the following code and it does not work for
Receipt printers I used Generic Text Driver for that
printer. What is the solution to print on receipt printer?

Thanks for your help.

david
--------------------

  Public Class TextFilePrintDocument
        Inherits PrintDocument

        Private printFont As Font
        Private streamToPrint As StreamReader

        Public Sub New(ByVal streamToPrint As
StreamReader)
            MyBase.New()
            Me.streamToPrint = streamToPrint
        End Sub

        'Override OnBeginPrint to set up the font we are
going to use
        Protected Overrides Sub OnBeginPrint(ByVal ev As
PrintEventArgs)
            MyBase.OnBeginPrint(ev)
            printFont = New Font("Arial", 10)
        End Sub

        'Override the OnPrintPage to provide the printing
logic for the document
        Protected Overrides Sub OnPrintPage(ByVal ev As
PrintPageEventArgs)

            MyBase.OnPrintPage(ev)

            Dim lpp As Single = 0
            Dim yPos As Single = 0
            Dim count As Integer = 0
            Dim leftMargin As Single =
ev.MarginBounds.Left
            Dim topMargin As Single = ev.MarginBounds.Top
            Dim line As String

            'Work out the number of lines per page
            'Use the MarginBounds on the event to do this
            lpp = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics)

            'Now iterate over the file printing out each
line
            'NOTE WELL: This assumes that a single line
is not wider than the page width
            'Check count first so that we don't read line
that we won't print
            line = streamToPrint.ReadLine()
            While (count < lpp And line <> Nothing)

                yPos = topMargin + (count *
printFont.GetHeight(ev.Graphics))

                ev.Graphics.DrawString(line, printFont,
Brushes.Black, leftMargin, _
                                       yPos, New
StringFormat())

                count = count + 1

                If (count < lpp) Then
                    line = streamToPrint.ReadLine()
                End If

            End While

            'If we have more lines then print another page
            If (line <> Nothing) Then
                ev.HasMorePages = True
            Else
                ev.HasMorePages = False
            End If

        End Sub

    End Class

  Private Sub Button22_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button22.Click
            'test for print
            Try
                Dim streamToPrint As StreamReader = New
StreamReader("unpaidck.dat")
                Try
                    'Assumes the default printer
                    Dim pd As TextFilePrintDocument = New
TextFilePrintDocument(streamToPrint)

                    Dim dlg As New PrintDialog()
                    dlg.Document = pd
                    Dim result As DialogResult =
dlg.ShowDialog()

                    If (result =
System.Windows.Forms.DialogResult.OK) Then
                        pd.Print()
                    End If

                Finally
                    streamToPrint.Close()
                End Try

            Catch ex As Exception
                MessageBox.Show("An error occurred
printing the file - " + ex.Message)
            End Try

        End Sub



Wed, 01 Dec 2004 00:32:49 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. VB & Epson TM88 Receipt Printer

2. Problem when using receipt printer (Epson TM-U300PA)

3. Using HP Printer Escape Sequences (aka Printer Passthrough Codes) in VB.Net

4. Help on Receipt printer....Please...Urgent

5. Help!!! Receipt Printer

6. problems printing on a zebra printer with printer.print

7. Having a problem to print receipt to the required length

8. Receipt Printing

9. How do I print a duplicate receipt?

10. Printing with printer.print - VB 6

11. Urgent -- how to print document on client's defualt printer using asp.net page

12. Post Net Bar code printing on Epson action 5000 printer

 

 
Powered by phpBB® Forum Software