We're sorry Aspose doesn't work properply without JavaScript enabled.

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());

How should this be realized in Java?
The basic way does not function:

String content = new String(data.readAllBytes(), StandardCharsets.UTF_8);

This ends up with additional bytes, which will cause an exception in the BarcodeGenerator like
“Maximum characters limit reached for BINARY compaction mode and 2 error correction level.
Encoded data length - 1345. Max available length - 1102.”

Doing something like:
byte[] dataBA = data.readAllBytes();
char[] charEncoded = new char[dataBA.length];
for (int i = 0; i < dataBA.length; ++i)
{
charEncoded[i] = (char)dataBA[i];
}
String content = new String(charEncoded);

doesn’t help either. The “problem” seems to be in the constructor of String.

@ThoKoc,

See and follow up your thread for updates and for your reference.