Giter Club home page Giter Club logo

barcoder's Introduction

Barcoder - Barcode Encoding Library

Build status

Lightweight Barcode Encoding Library for .NET Framework, .NET Standard and .NET Core. Additional packages are available for rendering the generated barcode to SVG or an image.

Please note that the image renderer (Barcoder.Renderer.Image) requires .NET6 or .NET8 because of the dependency on SixLabors.ImageSharp.Drawing and no longer works for .NET Framework. However, feel free to create your own renderer with another version or other image generation library.

Code ported from the GO project https://github.com/boombuler/barcode by Florian Sundermann.

Supported Barcode Types:

  • 2 of 5
  • Aztec Code
  • Codabar
  • Code 39
  • Code 93
  • Code 128
  • Code 128 GS1
  • Data Matrix (ECC 200)
  • Data Matrix GS1
  • EAN 8
  • EAN 13
  • KIX (used by PostNL)
  • PDF 417
  • QR Code
  • RM4SC (Royal Mail 4 State Code)
  • UPC A
  • UPC E

NuGet package

To install the main package:

PM> Install-Package Barcoder

To install the SVG renderer:

PM> Install-Package Barcoder.Renderer.Svg

To install the image renderer1:

PM> Install-Package Barcoder.Renderer.Image

Usage - render to SVG

var barcode = Code128Encoder.Encode("FOO/BAR/12345");
var renderer = new SvgRenderer();

using (var stream = new MemoryStream())
using (var reader = new StreamReader(stream))
{
    renderer.Render(barcode, stream);
    stream.Position = 0;

    string svg = reader.ReadToEnd();
    Console.WriteLine(svg);
}

Usage - render to PNG, JPEG, GIF or BMP

Example for rendering to PNG:

var barcode = QrEncoder.Encode("Hello World!");
var renderer = new ImageRenderer(new ImageRendererOptions { ImageFormat = ImageFormat.Png });

using (var stream = new FileStream("output.png", FileMode.Create))
{
    renderer.Render(barcode, stream);
}

Supported image formats can be found here

Footnotes

  1. The Barcoder.Renderer.Image package depends on the cross-platform SixLabors.ImageSharp.Drawing library. So when using this package, also respect their LICENSE.

barcoder's People

Contributors

brandscill avatar edweij avatar h3x4d3c1m4l avatar huysentruitw avatar int32overflow avatar lamerxaker avatar mrozean avatar mschuepbach avatar tinohager avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

barcoder's Issues

Set width and height of barcode

I'm using your barcode generator and I want to thank you for sharing it with us! Right now I'm struggling with one thing. Is it done on purpose so that the width and height cannot be set? I wanted to set the width of the generated bar code and tried that by accessing Bounds, which is a struct...so its meant to be only readable.
Is there a way to set the width and heigt of the barcode before generating it?

QR Code render thows an exception

I installed these two packages as described in the documentation, the error thows in my netcoreapp3.1

  • Barcoder
  • Barcoder.Renderer.Image
var barcode = QrEncoder.Encode(qrcode.Content, Barcoder.Qr.ErrorCorrectionLevel.M, Encoding.Auto);
var renderer = new ImageRenderer(imageFormat: Barcoder.Renderer.Image.ImageFormat.Png);

using (var ms = new MemoryStream())
{
	renderer.Render(barcode, ms);
	var imageData = ms.ToArray();
	this._skCanvas.DrawBitmap(SKBitmap.Decode(imageData), x, y);
}

image

QR Code with different width and height pixel sizes

Hello, I've been trying to work out if this is possible.

Can we set the length and height pixel / block sizes to be different? for example: its currently like 32 x 32 blocks, I want to set it so that it's like 16 x 64 blocks.

Thanks

Is it possible to use this in SSRS

Hi,

We have tested this in a C# app and it worked well. Thank you.

Do you know if it is possible to use this in a SSRS project (Reporting Services)?

Thank you,
Justin

Barcode numbers not displayed sometimes

Hi,
Im using barcoder in Xamarin forms, to print out a bar code, working fine on some machines
and on others not... I got the code image without the numbers below as attached
barcode

Any help?

DataMatrix with multiple extents?

Does this library support creating datamatrix barcodes that have multiple segments?

One labeling software I've seen called this "structured append".

image

I was able to get it to generate a barcode in this layout, but its restricted in size. Is it possible to automatically lengthen the CodeSize? For example, if I call DataMatrixEncoder.Encode(content, 16, 48, false); and it realizes there aren't enough segments to stuff the content in, it would just arbitrarily add more. It currently errors.

Code128 cannot read by scanner

Hey,
the Code128Encoder is not working :-(

            var code128 = Code128Encoder.Encode("123", false);
            var renderer = new ImageRenderer();
            using (var stream = new FileStream("output.png", FileMode.Create))
                renderer.Render(code128, stream);
            Process.Start("output.png");

I tried to read the code, but this code seems to be not valid!

Unicode in QR

In QR code, my Norwegian characters are wrong (æøåÆØÅ). I checked the code in the barcoder/src/Barcoder/Qr/InternalEncoders/UnicodeEncoder.cs file and found the following error.

  1. Byte order mark is missing.
  2. When data length is set, content length is used and not data length.

I corrected this in the code and now my Norwegian letters work fine. Here is my code now:

internal sealed class UnicodeEncoder : InternalEncoderBase
{
    public override (BitList, VersionInfo) Encode(string content, ErrorCorrectionLevel errorCorrectionLevel)
    {
        bool insertBom = false; // Insert Byte order mark (BOM) for UTF-8

        if (content == null) throw new ArgumentNullException(nameof(content));

        foreach (char item in content)
        {
            if (item > 127) // Check if BOM is needed
            {
                insertBom = true;
                break;
            }
        }
        
        byte[] data = System.Text.Encoding.UTF8.GetBytes(content);
        int dataLength = insertBom ? data.Length + 3 : data.Length;

        EncodingMode encodingMode = EncodingMode.Byte;
        var versionInfo = VersionInfo.FindSmallestVersionInfo(errorCorrectionLevel, encodingMode, dataLength * 8);
        if (versionInfo == null)
            throw new InvalidOperationException("Too much data to encode");

        var bits = new BitList();
        bits.AddBits((uint)encodingMode, 4);
        bits.AddBits((uint)dataLength, versionInfo.CharCountBits(encodingMode));

        if (insertBom) // Insert BOM
        {
            bits.AddByte(239);
            bits.AddByte(187);
            bits.AddByte(191);
        }

        foreach (var b in data)
            bits.AddByte(b);
        AddPaddingAndTerminator(ref bits, versionInfo);
        return (bits, versionInfo);
    }
}

Add GS1 Support to Code-128

Now the GS1 Encoder is implemented it is easy to implement this as an optional overload on the Code-128 Barcode Type.

I've raised the following PR #20 for this small change along with a test, would be good to get it merged into main branch as this would solve a gap we currently have.

Update to SixLabors.ImageSharp.Drawing 2.1.1

Are there any plans to update SixLabors.ImageSharp.Drawing to version 2.1.1?

Calling ImageRenderer.Render(IBarcode barcode, Stream outputStream) produces the error:

System.MissingMethodException: Method not found: 'Void SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder.set_Quality(System.Nullable`1<Int32>)'.

And also the author issued a advisory report because a vulnerability was found.

Data Matrix Code with UTF8 encoding?

According to my research, it is possible to use UTF-8 in data matrix codes in addition to the ISO-8859-1 (Latin-1) standard.
ECI is used for this. In DataMatrixSpecialCodewords I found ECI but no usage of it.

(How) can I use encodings other than ISO-8859-1 in a data matrix code?

Improve GS1 encoding

DataMatrix now has a very simplistic GS1 implementation. Let's create an encoder that understands all AI's and can be reused for Code128.

I'm using this issue to track progress while working on it.

White space around barcode image

Hi,

First of all, amazing work @huysentruitw. We are using your barcoder library for GS1 barcodes on stickers and it works flawlessly.
However, I do have one question. Whenever I generate the barcode as an image I get a white space (border?) around the barcode which takes up a lot of space in our word document which has a small size due to being a sticker. Is it possible to reduce this whitespace or remote it at all?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.