【问题标题】:Printing a .ZPL file to a zebra printer in vb.net. Visual Studio 2015 version在 vb.net 中将 .ZPL 文件打印到斑马打印机。视觉工作室 2015 版
【发布时间】:2015-10-21 15:08:43
【问题描述】:

我已经准备好原始 ZPL 文件,我只是不知道如何设置要发送到的打印机然后发送它。我该怎么做?

注意:我的计算机上有一个批处理脚本,我将所有 ZPL 文件默认为该脚本,这是一个将文件发送到我计算机上的热敏打印机的 shell 脚本。我想摆脱这种情况,并在我的应用程序中拥有所有命令,这样我就不必使用这样的外部脚本。

这是我现在拥有的代码,当它运行时会使用我的批处理脚本自动打开:

 Sub SaveLabel(ByRef labelFileName As String, ByRef labelBuffer() As Byte)
        ' Save label buffer to file
        Dim myPrinter As New PrinterSettings
        Dim LabelFile As FileStream = New FileStream(labelFileName, FileMode.Create)
        LabelFile.Write(labelBuffer, 0, labelBuffer.Length)
        LabelFile.Close()
        ' Display label
        DisplayLabel(labelFileName)
    End Sub

    Sub DisplayLabel(ByRef labelFileName As String)
        Dim info As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo(labelFileName)
        info.UseShellExecute = True
        info.Verb = "open"
        info.WindowStyle = ProcessWindowStyle.Hidden
        info.CreateNoWindow = True
        System.Diagnostics.Process.Start(info)
    End Sub

这是我的批处理脚本:

copy %1 \\%ComputerName%\Zebra

【问题讨论】:

    标签: vb.net printing visual-studio-2015 zpl zpl-ii


    【解决方案1】:

    在 VB.net 中复制批处理文件的确切功能:

    Dim filename As String = System.IO.Path.GetFileName(labelFileName)
    System.IO.File.Copy(
                    labelFileName,
                    Environment.ExpandEnvironmentVariables("\\%ComputerName%\Zebra\" & filename))
    

    这将使用System.IO 命名空间提供的方法复制文件。它还扩展了%COMPUTERNAME% 环境变量。这将替换 DisplayFile 子例程中的所有代码。

    【讨论】:

    • 我到处搜索试图在应用程序中复制它,我猜我看起来不够努力。谢谢您,先生,您结束了我 4 小时的绝望。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多