huysentruitw / barcoder

Lightweight Barcode Encoding Library for .NET Framework, .NET Standard and .NET Core.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

White space around barcode image

Mittchel opened this issue · comments

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?

I ran into this issue as well, but with the DataMatrix codes. we also wanted a thinner border for our application; I resorted to cloning the project locally, and making the edit needed.

suboptimal for a few reasons, but I'm not aware of any other way.

as I understand it, the width of the borders around the various barcodes are part of their specs, to help scanners identify the code. this makes me worry that there's reasons AGAINST allowing customizing them... all that being said: for our application, we're happy with thinner borders, and would appreciate the ability to customize them, as well!

Hi both, this is open-source, so please feel free to discuss or add a solution through a PR (with unit-tests if possible) for adding this as a feature. When adding properties or settings, please make sure not to break anything for other users of this library (the output should remain backwards compatible).

Hi, we're looking into getting rid of GDI+ and this margin is a minor annoyance.
Shall we pick this library as replacement we'll definitely send a PR this way.
Best regards.

It is actually quite easy to get around the problem:

   var barcode = DataMatrixEncoder.Encode(code);
    if (noMargin)
        barcode = new NoMarginBarcode(barcode); 

internal class NoMarginBarcode : IBarcode
{
    private readonly IBarcode inner;

    public NoMarginBarcode(IBarcode inner)
    {
        this.inner = inner;
    }

    public string Content => inner.Content;
    public Bounds Bounds => inner.Bounds;
    public int Margin => 0;
    public Metadata Metadata => inner.Metadata;
    public bool At(int x, int y) => inner.At(x, y);
}

The needed changes in the API appear trivial.

I have just released v2.0.0 which now uses "option" classes to pass configuration to the renderers. These new option classes now also include a property CustomMargin that allow you to override the margin on the renderer.