Click here to Skip to main content
15,886,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have develop a POS Application using Vb.net.
I write a text in notepad and from that i will print a receipt in Epson printer,
Now i need to auto cut the paper after the print complete using the vb.net code.

My code

VB
Private Sub print_notepad()
       Try
           streamToPrint = New StreamReader("D:\Backup\Ramesh\DATA\bill.txt")
           Try
               printFont = New Font("Lucida Console", 12)
               Dim pd As New PrintDocument()
               AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
               pd.Print()

           Finally
               streamToPrint.Close()
           End Try
       Catch ex As Exception
           MessageBox.Show(ex.Message)
       End Try
   End Sub



VB
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
      Dim linesPerPage As Single = 0
      Dim yPos As Single = 0
      Dim count As Integer = 0
      Dim leftMargin As Single = ev.MarginBounds.Left '...Left...
      Dim topMargin As Single = ev.MarginBounds.Top
      Dim line As String = Nothing

      ' Calculate the number of lines per page.
      linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

      ' Print each line of the file.
      While count < linesPerPage
          line = streamToPrint.ReadLine()
          If line Is Nothing Then
              Exit While
          End If
          yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
          ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
          count += 1
      End While
     
          ev.HasMorePages = True
      Else
          ev.HasMorePages = False
      End If
  End Sub




But it only print the text and not cut automatically.
Posted
Comments
SoMad 26-May-14 7:12am    
Is it a POS printer or just a normal printer?

I ask because Epson created an entire command set called ESC/POS specifically for handling POS printers. There are several commands defined for cutting the paper.

However, you should consider dropping your current approach and instead follow the advice given by Sergey here[^]

Soren Madsen
srameshsathy 27-May-14 5:50am    
Thanks for reply.
It's a Epson lx 300 printer.
I need a Vb.net code to cut the paper.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900