Giter Club home page Giter Club logo

Comments (6)

micjahn avatar micjahn commented on July 20, 2024 3

the following code snippet should work as expected:

`
[Test]
public void Hex2Pdf417()
{
var hexStr = "fe3009333137303130323031f9200134fe300120fc2006";
var byteArray = Enumerable.Range(0, hexStr.Length / 2).Select(x => Convert.ToByte(hexStr.Substring(x * 2, 2), 16)).ToArray();
var byteArrayAsString = new String(byteArray.Select(b => (char)b).ToArray());

     // encode the string as PDF417
     var writer = new BarcodeWriter
     {
        Format = BarcodeFormat.PDF_417,
        Options = new PDF417EncodingOptions
        {
           Height = 200,
           Width = 200,
           Margin = 10
        }
     };
     var bitmap = writer.Write(byteArrayAsString);

     // try to decode the PDF417
     var reader = new BarcodeReader
     {
        Options = new DecodingOptions
        {
           PossibleFormats = new List<BarcodeFormat>
           {
              BarcodeFormat.PDF_417
           },
           PureBarcode = true
        }
     };
     var result = reader.Decode(bitmap);

     // make sure, the result is the same as the original hex
     var resultBackToBytes = result.Text.Select(c => (byte)c).ToArray();
     var resultAsHexString = String.Join("", resultBackToBytes.Select(b => b.ToString("x2")));

     Assert.That(resultAsHexString, Is.EqualTo(hexStr));
  }

`

from zxing.net.

micjahn avatar micjahn commented on July 20, 2024 3

Both errors are related to version 0.14 of ZXing.Net.
They are fixed in the next version.
Please try the current source code from the repository.

from zxing.net.

jl-yndu avatar jl-yndu commented on July 20, 2024

The following HEX throws the error:

Non-encodable character detected: (Unicode: 132)

And when i decode the barcode here online-barcode-reader.inliteresearch.com, it shows that the saved HEX data isn't the original HEX. "FE" is saved as "5F".

30303142415243303030FE

from zxing.net.

micjahn avatar micjahn commented on July 20, 2024

Please post a complete stack trace of your error ("Non-encodable...").
For me it works like a charm.
And I checked the generated barcode against you online reader and I can't see any wrong value.
Did you really use my method for the conversion from hex to string?

from zxing.net.

jl-yndu avatar jl-yndu commented on July 20, 2024

Full Error
ZXing.WriterException wurde nicht behandelt.
HResult=-2146233088
Message=Non-encodable character detected: (Unicode: 132)
Source=zxing
StackTrace:
bei ZXing.PDF417.Internal.PDF417HighLevelEncoder.determineConsecutiveBinaryCount(String msg, Byte[] bytes, Int32 startpos) in C:\ZXing.Net.0.14.0.0\Source\lib\pdf417\encoder\PDF417HighLevelEncoder.cs:Zeile 739.
bei ZXing.PDF417.Internal.PDF417HighLevelEncoder.encodeHighLevel(String msg, Compaction compaction, Encoding encoding, Boolean disableEci) in C:\ZXing.Net.0.14.0.0\Source\lib\pdf417\encoder\PDF417HighLevelEncoder.cs:Zeile 258.
bei ZXing.PDF417.Internal.PDF417.generateBarcodeLogic(String msg, Int32 errorCorrectionLevel) in C:\ZXing.Net.0.14.0.0\Source\lib\pdf417\encoder\PDF417.cs:Zeile 682.
bei ZXing.PDF417.PDF417Writer.bitMatrixFromEncoder(PDF417 encoder, String contents, Int32 width, Int32 height, Int32 margin, Int32 errorCorrectionLevel) in C:\ZXing.Net.0.14.0.0\Source\lib\pdf417\PDF417Writer.cs:Zeile 142.
bei ZXing.PDF417.PDF417Writer.encode(String contents, BarcodeFormat format, Int32 width, Int32 height, IDictionary2 hints) in C:\ZXing.Net.0.14.0.0\Source\lib\pdf417\PDF417Writer.cs:Zeile 111. bei ZXing.MultiFormatWriter.encode(String contents, BarcodeFormat format, Int32 width, Int32 height, IDictionary2 hints) in C:\ZXing.Net.0.14.0.0\Source\lib\MultiFormatWriter.cs:Zeile 79.
bei ZXing.BarcodeWriterGeneric1.Encode(String contents) in C:\ZXing.Net.0.14.0.0\Source\lib\BarcodeWriterGeneric.cs:Zeile 72. bei ZXing.BarcodeWriterGeneric1.Write(String contents) in C:\ZXing.Net.0.14.0.0\Source\lib\BarcodeWriterGeneric.cs:Zeile 86.
bei Weiss.Form1.GeneratePDF417(String hexStr) in C:\Users\xxx\Desktop\xxx\xxx\xxx\xxx\Form1.cs:Zeile 696.
bei Weiss.Form1.GetWeiss() in C:\Users\xxx\Desktop\xxx\xxx\xxx\xxx\Form1.cs:Zeile 159.
bei Weiss.Form1..ctor() in C:\Users\xxx\Desktop\xxx\xxx\xxx\xxx\Form1.cs:Zeile 21.
bei Weiss.Program.Main() in C:\Users\xxx\Desktop\xxx\xxx\xxx\xxx\Program.cs:Zeile 19.
bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()
InnerException:

Code:
var bitmap = writer.Write(byteArrayAsString); (throws the error)

` private byte[] GeneratePDF417(string hexStr)
{
hexStr = "30303142415243303030";
var byteArray = Enumerable.Range(0, hexStr.Length / 2).Select(x => Convert.ToByte(hexStr.Substring(x * 2, 2), 16)).ToArray();
var byteArrayAsString = new String(byteArray.Select(b => (char)b).ToArray());
var writer = new BarcodeWriter
{
Format = BarcodeFormat.PDF_417,
Options = new PDF417EncodingOptions
{
Height = 200,
Width = 200,
Margin = 10
}
};
var bitmap = writer.Write(byteArrayAsString);

        using (var stream = new MemoryStream())
        {
            bitmap.Save(stream, ImageFormat.Png);
            return stream.ToArray();
        }
    }`

from zxing.net.

jl-yndu avatar jl-yndu commented on July 20, 2024

Thanks a lot! It's working perfectly with the current version from the source code!

from zxing.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.