如何使用 zxing.net 处理 Code128 中的特殊字符

How to handle special characters in Code128 using zxing.net

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

System.ArgumentException: Bad character in input:

不用说,没有制表符,它就像一个魅力。

报告中使用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

问题:

我最终得到 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。