1

I created a SSRS Report which contains a few Code128 Barcodes. The Barcodes are generated using the latest zxing.net library. I would like to include tabs (char(9)) in an Code128 Barcode. But it fail with the following exception message:

System.ArgumentException: Bad character in input:

Needless to say that it works like a charm without the tabulator character.

The GetBarCodeHorizontal is used in the report to generate the barcodes. However, for testing purpose i wrapped it into a visual studio vb project:

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

Questions:

  • How can i solve this problem?
  • Is this a limitation of the zxing library?
  • Is there any suitable workaround (or maybe even another library)?
Joel
  • 4,862
  • 7
  • 46
  • 71
  • why are you trying to use tabs in the barcode? maybe with a little background we could come up with an alternative. – Nefariis Nov 04 '15 at 23:18
  • The barcode ist used to insert information into a console based legacy system. The Tab is used to switch to the next field. The Barcode should look like: [MaterialNumber] [Tab] [Quantity] [Tab] [Batch] [Tab] [Location]. Do you know another library which is working with SSRS? – Joel Nov 05 '15 at 09:25
  • 1
    Could you use another chacter to switch to the next field, like a pipe "|"? zxing is the standard - here are some other options though - http://stackoverflow.com/questions/8116990/looking-for-best-barcode-scanner-library-besides-zxing ... I would see if I could change the legecy first.... The problem you are going to run into is that "tabular" is not apart of any encoding tables (utf-8, iso, ect.) so I dont see a way for "tabular" to ever work regardless of the library... Maybe if you can find a table that has it, then find the library that supports that table - but outside of that.... – Nefariis Nov 05 '15 at 18:38
  • Thank you for your comments. Unfortunately, there is no other way beside the the tab key to switch to the next text field. I ended up with another library. – Joel Nov 10 '15 at 13:17

1 Answers1

0

I ended up with another (free) library which turns out to work very well.

There is also a tutorial how to embed barcodes into SSRS for this specific library.

For those of interest here is my code to create the barcodes:

 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

The barcode data comes directly from the query as shown here:

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) creates a Tab.

Joel
  • 4,862
  • 7
  • 46
  • 71