Comments (6)
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.
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.
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.
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.
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, IDictionary
2 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.BarcodeWriterGeneric
1.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.
Thanks a lot! It's working perfectly with the current version from the source code!
from zxing.net.
Related Issues (20)
- MSI barcode reading fails
- RobiniaDocs API Explorer
- A different CODE_39 barcode HOT 1
- Add some unsafe methods? HOT 1
- 0.16.6 vs 0.16.9 HOT 1
- Missing BitmapLuminanceSource in the ZXing.Net Nuget Package: HOT 1
- Version out dated while opening in vs22, using version 4.0 HOT 3
- Scannig QR Code with Oppo devices doesn't work HOT 2
- BitArray.xor() should check length of both arrays HOT 3
- A small log bug HOT 1
- 如何设置条形码的尺寸以及密度 HOT 1
- Renderer for net8.0-android? HOT 4
- ZXing.Net Bindings for SkiaSharp Package missing Linux HOT 4
- Upgrade SkiaSharp - current version had Vulnerabilities HOT 5
- zxing.net is missing NuGet package README file
- Can't encode € symbol to Qr. HOT 3
- Unable to parse this QR code, I don't know why HOT 1
- QRCODE type error parsing to UPC-E type HOT 1
- UPC/EAN Extension 2/5 does not read the 2/5 digit extension
- Can someone finally fix the example usage in README?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zxing.net.