从vb.net直接将文本打印到打印机
问题描述:
我先创建了一个脚本来创建字符串文本,我想在pos打印机中打印,然后创建一个记事本文件并触发打印命令在vb.net中使用shell但我想知道并找出任何替代方法而不是记事本我可以将打印件直接发送到打印机,这是一台USB打印机,以所需的格式将文本打印到打印机,请帮助。 br $> b $ b
Hi,
I have created a script first to create string text which i want to print in the pos printer and then creating a notepad file and firing the print command using shell in vb.net but i want to know and find out any alternative method available instead of notepad i can send the print directly to printer which is a usb printer to print the text to the printer in desired format, kindly help.
printtext = Chr(9) & "mytext1" & vbCrLf
printtext = printtext & Chr(9) & "mytext2" & vbCrLf
printtext = printtext & Chr(9) & "mytext3" & vbCrLf
printtext = printtext & Chr(9) & "mytext4" & vbCrLf
printtext = printtext & Chr(9) & "mytext5" & vbCrLf
printtext = printtext & Chr(9) & "mytext6" & vbCrLf
Dim printpath As String = \tprint.txt"
File.WriteAllText(printpath, printtext)
Dim sCommand As String
sCommand = "start /min notepad /P " + "\tprint.txt"
Shell("cmd.exe /c " & sCommand, AppWinStyle.Hide)
答
如果打印机是网络打印机,则通过传递Text和PrinterName来尝试此方法prt,然后指定完整的网络路径。例如。\\sharedlocation\printername
Try this method "prt" by passing the "Text" and "PrinterName", if the printer is a network printer then specify the full network path. eg. "\\sharedlocation\printername"
Public Class PrintHelper
Friend TextToBePrinted As String
Public Sub prt(ByVal text As String, ByVal printer As String)
TextToBePrinted = text
Dim prn As New Printing.PrintDocument
Using (prn)
prn.PrinterSettings.PrinterName = printer
AddHandler prn.PrintPage, _
AddressOf Me.PrintPageHandler
prn.Print()
RemoveHandler prn.PrintPage, _
AddressOf Me.PrintPageHandler
End Using
End Sub
Private Sub PrintPageHandler(ByVal sender As Object, _
ByVal args As Printing.PrintPageEventArgs)
Dim myFont As New Font("Courier New", 9)
args.Graphics.DrawString(TextToBePrinted, _
New Font(myFont, FontStyle.Regular), _
Brushes.Black, 50, 50)
End Sub
End Class
希望这会有所帮助。 ..
hope this will help...
这是从VB.NET发送原始文本到任何打印机的直接方式 http ://support.microsoft.com/kb/322090 [ ^ ]
This is the direct way for sending raw text to any printer from VB.NET http://support.microsoft.com/kb/322090[^]
使用打印文件
如果你想要我给的代码。
use print document
if u want code i will give.