Free Support Forum - aspose.com

Generate a PDF471 Barcode from byte array

Hello,

I need to generate a PDF471 Barcode from a byte array and not from text.
How can this be done?

Thanks an regards,

Jürgen

Seems someone found a solution with aspose:


But I cant find the objects BarCodeBuilder and SetBinaryCodeText …

@juergen.debus,

In newer APIs, BarCodeBuilder is replaced by Aspose.BarCode.Generation.BarcodeGenerator class which does not have such a method. I think you may easily get string from your byte array using .NET API. See the following line of code for your reference:
e.g.
Sample code:

var codeText = System.Text.Encoding.Default.GetString(data);

Thanks, but with this solution the barcode reader needs to do the same with the same enconding.
No other solution available?

@juergen.debus,
Yes, you are right. You have to convert the read string into byte array yourself. There is no direct way to retrieve byte array using BarCode reader. Please feel free to write us back if you have any other query in this regard.

It is better to encode manually to char array because Default codepage can sometimes encode incorrectly.

byte[] myEncodeData = new byte[] { 0, 10, 190, 161, 153, 142, 255 };
byte[] myReadData = null;


char[] charEncoded = new char[myEncodeData.Length];
for (int i = 0; i < myEncodeData.Length; ++i)
    charEncoded[i] = (char)myEncodeData[i];
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Pdf417, new string(charEncoded)))
{
    gen.Parameters.Barcode.Pdf417.Pdf417CompactionMode = Pdf417CompactionMode.Binary;
    using (BarCodeReader read = new BarCodeReader(gen.GenerateBarCodeImage(), DecodeType.Pdf417))
        if (0 < read.ReadBarCodes().Length)
            myReadData = (byte[])read.FoundBarCodes[0].CodeBytes.Clone();
}

MessageBox.Show("Arrays are equal: " + System.Linq.Enumerable.SequenceEqual(myEncodeData, myReadData).ToString().ToLower());