Search code examples
c#itext7

Problem for generate a 16x48 datamatrix with iText7


I have a problem with this code :

BarcodeDataMatrix barreCode = new BarcodeDataMatrix("12345678");
barreCode.SetOptions(BarcodeDataMatrix.DM_EDIFACT);
barreCode.SetWidth(48);
barreCode.SetHeight(16);
PdfFormXObject xobj = barreCode.CreateFormXObject(_pdfDoc);

This code throw a System.IndexOutOfRangeException 

If I remove the lines

barreCode.SetWidth(48);
barreCode.SetHeight(16);

it works fine, but i need to generate a datamatrix with these 2 options.

Can anyone help me ?

Thank you


Solution

  • In your case you should use the constructor without parameters and specify your settings first, and set the code afterwards. Example:

    BarcodeDataMatrix barcode = new BarcodeDataMatrix();
    barcode.SetOptions(BarcodeDataMatrix.DM_EDIFACT);
    barcode.SetWidth(48);
    barcode.SetHeight(16);
    barcode.SetCode("12345678");