Generate barcode using Visual Studio local report or SSRS

Follow below steps to generate barcode in SQL Server Reporting Services(SSRS) or Visual Studio local reports.

  1. Download open source ZXing.Net.0.14.0.0 component for Barcode or QRCode generation.
  2. Create a Visual Studio project and add a Report
    barcode-add-item
  3. Create datasets for the report.
  4. Select Report and press F4 to open report properties.
  5. Select Properties > Code.
    report-propertis
  6. Write Following code in custom code text box.
    Public Function getBarCode39Horizontal(ByVal s As String) As Byte()
    Dim writer As New ZXing.BarcodeWriter()
    Dim ms AS System.IO.MemoryStream = new System.IO.MemoryStream()writer.Format = ZXing.BarcodeFormat.CODE_39
    writer.Options = New ZXing.Common.EncodingOptionswriter.Options.Width = 125
    writer.Options.Height = 100
    
    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
    
    Public Function getBarCode39Vertical(ByVal s As String) As Byte()
    Dim writer As New ZXing.BarcodeWriter()
    Dim ms AS System.IO.MemoryStream = new System.IO.MemoryStream()
    
    writer.Format = ZXing.BarcodeFormat.CODE_39
    writer.Options = New ZXing.Common.EncodingOptions
    
    writer.Options.Width = 420
    writer.Options.Height = 110
    
    Dim bmp As System.Drawing.Bitmap = writer.Write(s)
    
    bmp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone)
    bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
    
    Dim imagedata as byte()
    imagedata = ms.GetBuffer()
    Return imagedata
    End Function

     

  7. Select Reference in same property window.
    report-reference
  8. Add reference to downloaded Zxing component (zxing.dll) and System.Drwaing.
  9. Now add an image on report and right click on it and select Image Properties.
  10. In general tab select the image source as database.
  11. click on Fx icon of use this field combo and write following code.
    =Code.getBarCode39Vertical(Fields!<database field name>.Value
  12. In above code replace <database field name> with your report data field.
  13. Compile and execute the application.
    ssrs-bar-code printing

    If you required any further information or any sample code please contact me at arwind@adeptlab.com. 

Arwind Yadav

Arwind Yadav

Arwind Yadav, is a IT professional with over twelve years of experience in conceptualizing, designing and developing software applications. He loves building web apps and has also well versed with all the aspects of e-commerce solutions, mobile applications and automation.

You may also like...

3 Responses

  1. Hi there, just became aware of your blog through Google, and found that it’s really informative.
    I am gonna watch out for brussels. I’ll be grateful if you continue this in future.

    Lots of people will be benefited from your
    writing. Cheers!

  2. I think this is one of the most significant info for me.
    And i am glad reading your article. But wanna remark on few general things, The site style is perfect, the articles is really excellent :
    D. Good job, cheers

  3. Thanks on your marvelous posting! I genuinely enjoyed reading it, you are a great author.

    I will always bookmark your blog and will often come back
    in the future. I want to encourage you to definitely
    continue your great posts, have a nice evening!