Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,i am using vb.net framework 4 and i have to print through a POS Printer.please help me.
how will i do that.thanks in advance

my code is given below.but its not working and giving error in
VB
e.Graphics.DrawString(" NOTA DE PLATA", printFont10B, Brushes.Black, 10, 10)
.....error says Object reference not set to an instance of an object.

VB
Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
       Dim i As Integer
       Dim printFont10B = New Font("Lucida Console", 10, FontStyle.Bold)
       Dim printFont9R = New Font("Arial", 9, FontStyle.Regular)
       Dim printFont8R = New Font("Arial", 8, FontStyle.Regular)

       e.Graphics.DrawString(" NOTA DE PLATA", printFont10B, Brushes.Black, 10, 10)
       e.Graphics.DrawString("-----------------------------------------", New Font(Me.Font.FontFamily, 8, FontStyle.Regular), Brushes.Black, 10, 70)
       e.Graphics.DrawString("Numar nota: ", printFont9R, Brushes.Black, 10, 80)
       e.Graphics.DrawString("|Denumire | Cant |Pret |", printFont9R, Brushes.Black, 10, 100)
   End Sub




please help me
Posted
Updated 9-Jun-14 1:20am
v2
Comments
[no name] 9-Jun-14 6:54am    
"its not working" tells us nothing about your problem. All you are doing is drawing some strings, what did you expect to happen? See http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx
BIBASWAN 9-Jun-14 7:20am    
sorry i have not write about the error... its not working and giving error in e.Graphics.DrawString(" NOTA DE PLATA", printFont10B, Brushes.Black, 10, 10).....error says Object reference not set to an instance of an object.
Richard MacCutchan 9-Jun-14 7:27am    
Use your debugger to step through the code and see which reference has not been set to a valid object.

My suggestion is you learn which commands your POS printer supports (likely ESC/POS commands) and then construct the commands in VB and send it directly to the printer by using this code http://support.microsoft.com/kb/322090[^]
PrintDocument approach should work (you have not clearly specified what is the error you got there) but comparing it to sending printer commands, PrintDocument will be very slow.
 
Share this answer
 
Imports System.IO
Imports System.Drawing.Printing


Public Class Form1
Public egraphics As Graphics
Public prnDocument As New System.Drawing.Printing.PrintDocument

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Click
Dim psize As New Printing.PaperSize("A4", 842, 595)

AddHandler prnDocument.PrintPage, AddressOf PrintPage

prnDocument.DefaultPageSettings.PaperSize = psize
prnDocument.DefaultPageSettings.Margins.Top = 0
prnDocument.DefaultPageSettings.Margins.Left = 0
prnDocument.DefaultPageSettings.Margins.Bottom = 0
prnDocument.DefaultPageSettings.Margins.Right = 0
prnDocument.OriginAtMargins = True


prnDocument.Print()
End Sub

Private Sub PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim fReportFont As System.Drawing.Font

egraphics = e.Graphics
egraphics.PageUnit = GraphicsUnit.Point
fReportFont = New System.Drawing.Font(Trim("Helvetica"), 60, FontStyle.Regular)
egraphics.DrawString("This is to test", fReportFont, New SolidBrush(Color.Black), 100, 200)

End Sub

End Class
 
Share this answer
 

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