VB.net如何直接在客户端打印文本

时间:2014-06-30 00:15:54

标签: javascript vb.net printing vbscript

我正在尝试将一个变量(某些文本)打印到打印机(作为创建条形码标签Zebra打印机3488的通用文本),它在服务器端使用Printing.PrintDocument时工作正常,我需要打印所有内容变量" TextToBePrinted"或文本框直接打印机没有弹出, 我知道我必须使用JavaScript,Activex或vbscript,所以如果有人可以帮助我欣赏

谢谢

滨田

------以下代码在服务器端正常工作-----

Imports System.Drawing.Printing
Imports System.Drawing

Dim printernameD As String
TextToBePrinted = TextBox3.Text

Dim prn As New Printing.PrintDocument
Using (prn)

    TextToBePrinted = "Line 1111111111111" & Environment.NewLine
    TextToBePrinted = TextToBePrinted & "Line 2222222222222222" & Environment.NewLine
    TextToBePrinted = TextToBePrinted & "Line 3333333333333333" & Environment.NewLine
    TextToBePrinted = TextToBePrinted & "Line 4444444444444444" & Environment.NewLine

    AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
    prn.Print()
    RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
End Using

Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)

    Dim myFont As New Font("Times New Roman", 12) ' font

    Dim drawFont As New Font("EAN 13", 12)
    Dim drawBrush As New SolidBrush(Color.Black)
    ' Create rectangle for drawing. 
    Dim x As Single = 50.0F
    Dim y As Single = 50.0F
    Dim width As Single = 200.0F
    Dim height As Single = 50.0F
    Dim drawRect As New RectangleF(x, y, width, height)
    ' Set format of string. 
    Dim drawFormat As New StringFormat
    drawFormat.Alignment = StringAlignment.Center

    args.Graphics.DrawString(TextToBePrinted, New Font(myFont, FontStyle.Regular), Brushes.Black, 5, 5)

End Sub

2 个答案:

答案 0 :(得分:0)

网络服务器无法命令打印机。最接近的是服务器生成PostScript(实际上是PDF)文档,然后用户下载并打印该文档。

幸运的是,您可以重复使用现有代码:只需安装Adobe Acrobat Pro(或其他一些PDF打印机驱动程序)并更改代码以打印到该虚拟打印机,识别PDF的保存位置,然后将其返回到客户。

答案 1 :(得分:-1)

POS: get a website to print directly to a defined local printer/s

此页面上的第一个答案解释了如何使用Chrome Kiosk模式进行打印,这是我在阅读该帖子之前从未听说过的,但听起来很有希望。希望它有所帮助。