如何使用zxing.net

时间:2015-11-04 09:03:00

标签: vb.net reporting-services barcode zxing ssrs-2012

我创建了一个SSRS报告,其中包含一些Code128条形码。条形码使用最新的zxing.net库生成。我想在Code128条形码中包含制表符(char(9))。但它失败并出现以下异常消息:

  

System.ArgumentException:输入中的错误字符:

毋庸置疑,它就像没有制表人角色的魅力。

报告中使用GetBarCodeHorizontal生成条形码。但是,出于测试目的,我将其包装到visual studio vb项目中:

Class MainWindow
    Public Function GetBarCodeHorizontal(ByVal s As String, ByVal width As Integer) As Byte()
        Dim writer As New ZXing.BarcodeWriter()
        Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream()

        writer.Format = ZXing.BarcodeFormat.CODE_128
        writer.Options = New ZXing.Common.EncodingOptions
        writer.Options.Width = width
        writer.Options.Height = 60
        writer.Options.PureBarcode = False
        'writer.Options.Hints.Add(ZXing.EncodeHintType.CHARACTER_SET, "UTF-8")

        Dim bmp As System.Drawing.Bitmap = writer.Write(s)

        bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
        Dim imagedata As Byte()
        imagedata = ms.GetBuffer()
        Return imagedata
    End Function


    Private Sub MainWindow_OnLoaded(sender As Object, e As RoutedEventArgs)
        Try
            Dim barCodeHorizontal = GetBarCodeHorizontal("3999999   80  1XXXXXX8    r1XX3", 200)
        Catch ex As Exception
            Console.WriteLine(ex)
        End Try
    End Sub
End Class

问题:

  • 我该如何解决这个问题?
  • 这是zxing库的限制吗?
  • 是否有合适的解决方法(或者甚至是其他库)?

1 个答案:

答案 0 :(得分:0)

我最终得到another (free) library,结果非常好。

还有tutorial如何将条形码嵌入到此特定库的SSRS中。

对于那些感兴趣的人,我的代码是创建条形码:

 Public Function GetBarcode(ByVal text As String, ByVal barcodeWidth As Integer, ByVal barcodeHeight As Integer) As Byte()
        Dim b As System.Drawing.Bitmap
        Dim bar As New BarcodeLib.Barcode
        bar.Alignment = BarcodeLib.AlignmentPositions.CENTER

        bar.IncludeLabel = False
        b = bar.Encode(BarcodeLib.TYPE.CODE128, text, barcodeWidth, barcodeHeight)
        Dim bitmapData As Byte() = Nothing
        Using ms As New System.IO.MemoryStream()
            b.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
            bitmapData = ms.ToArray()
        End Using
        Return bitmapData
    End Function

条形码数据直接来自查询,如下所示:

SELECT        MilkrunID, Code, Quantity, Batch, PickLocation, Code + CHAR(9) + CAST(Quantity AS NVARCHAR(20)) + CHAR(9) + Batch + CHAR(9) + PickLocation AS Barcode
FROM            Tbl_ReportData_ProductionReplenishment_MilkrunSummary

char(9)创建一个Tab。