jueves, 30 de enero de 2014

Como imprimir en impresora zebra con zpl desde visual basic .net ean13 codebar

Primero debemos agregar la referencia a la siguiente libreria VisualBasic.PowerPacks.vs.dll

Luego declaramos:

Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6


Invocamos a la función entregando los datos que queremos que imprima y la cantidad de copias.


Private Sub BarCodeEAN13(ByVal Cliente As String, ByVal Codigo As String, ByVal Descripcion As String, ByVal NumCopias As Integer)
        Dim Columna As Integer = 0

        Dim Printer As New Printer
        Dim prt As Printer
        For Each prt In Printers
            If prt.DeviceName = ImpresoraSeleccionada Then
                Printer = prt
                Exit For
            End If
        Next

        For i As Integer = 1 To NumCopias
            Columna = Columna + 1
            'Columna 1
            If Columna = 1 Then
                'Codigo de barra
                Printer.Print("^XA")
                Printer.Print("^FO35,90^BY2")
                Printer.Print("^BEN,50,Y,N")
                Printer.Print("^FD" & Trim(Codigo) & "^FS")
                'Descripcion del producto
                Printer.Print("^FO20,35")
                Printer.Print("^FB230,4.5,,")
                Printer.Print("^ADN, 11, 7^FD" & Descripcion & "^FS")
                'Tienda
                Printer.Print("^FO25,10")
                Printer.Print("^A0N,30,30^FD" & Cliente & "^FS")
            End If
            'Columna 2
            If Columna = 2 Then
                'Codigo de barra
                Printer.Print("^FO300,90^BY2")
                Printer.Print("^BEN,50,Y,N")
                Printer.Print("^FD" & Trim(Codigo) & "^FS")
                'Descripcion del producto
                Printer.Print("^FO285,35")
                Printer.Print("^FB230,4.5,,")
                Printer.Print("^ADN, 11, 7^FD" & Descripcion & "^FS")
                'Tienda
                Printer.Print("^FO290,10")
                Printer.Print("^A0N,30,30^FD" & Cliente & "^FS")
            End If

            'Columna 3
            If Columna = 3 Then
                'Codigo de barra
                Printer.Print("^FO570,90^BY2")
                Printer.Print("^BEN,50,Y,N")
                Printer.Print("^FD" & Trim(Codigo) & "^FS")
                'Descripcion del producto
                Printer.Print("^FO555,35")
                Printer.Print("^FB230,4.5,,")
                Printer.Print("^ADN, 11, 7^FD" & Descripcion & "^FS")
                'Tienda
                Printer.Print("^FO560,10")
                Printer.Print("^A0N,30,30^FD" & Cliente & "^FS")
            End If
            If Columna = 3 Then
                Printer.Print("^XZ")
                'Printer.EndDoc()
                Columna = 0
            End If
            If i = NumCopias Then
                Printer.Print("^XZ")
            End If
        Next
        Printer.EndDoc()
    End Sub

Fuente: