如何通过Pos打印机进行打印 [英] How Do I Print Through A Pos Printer
本文介绍了如何通过Pos打印机进行打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我正在使用vb.net框架4,我必须通过POS打印机打印。请帮助我。
我将如何做到这一点。提前谢谢
我的代码如下所示。但是它没有工作并且在
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
e.Graphics.DrawString(" NOTA DE PLATA", printFont10B, Brushes.Black, 10, 10)
.....错误说对象引用未设置为对象的实例。
.....error says Object reference not set to an instance of an object.
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
推荐答案
我的建议是你学习哪些命令你的POS打印机支持(可能是ESC / POS命令)然后在VB中构造命令并使用此代码将其直接发送到打印机 http:/ /support.microsoft.com/kb/322090 [ ^ ]
PrintDocument方法应该有效(你没有明确指出你在那里遇到的错误)但是将它与发送打印机命令进行比较,PrintDocument会非常慢。
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.
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)处理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(这是测试,fReportFont,New SolidBrush(Color.Black),100,200)
End Sub
结束班
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
这篇关于如何通过Pos打印机进行打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文