Search code examples
zxingdatamatrix

zxing Datamatrix generator creating rectangular barcode which can't be scanned


I am using barcodewriter to write datamatrix barcoe. While most of the times it creates correct square style datamatrix barcode, for some of text it creates rectangular shaped barcode.

For inputData like below it creates rectangular barcode 8004600000070000017 C/TH PAUL PENGELLY C/TH NICKY PARSONS C/TH ROSEMARIE BARTOLOME

while for others it creates square styled: CTH HEKT-WOODROW MORGAN 800460000007 800460000007000001700000

i am usinf this code to generate code: BarcodeWriter writer = new BarcodeWriter() { Format = BarcodeFormat.DATA_MATRIX };
var img = writer.Write(inputData); return new Bitmap(img);

img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); dto.BarcodeImage = ms.ToArray();

How can I make sure that I always get Square shaped datamatrix? I have alread tried adding height,width options.

Thanks


Solution

  • There is SymbolShape option which can be used to force shape .
     DatamatrixEncodingOptions options = new DatamatrixEncodingOptions()
                {
                    Height = 300,
                    Width = 300,
                    PureBarcode = true,
                    Margin = 1,
                    SymbolShape = SymbolShapeHint.FORCE_SQUARE
                };