Closed themars closed 8 years ago
Well, it is trying to turn that string into a set of PDF417 codewords for barcode generation. I'm not sure what you want the end result to be, but with that initialization I wouldn't expect a scan to return data.join].pack("H*")
.
Maybe you want to try using the raw_codewords
method? That would look like this:
barcode = PDF417.new
barcode.raw_codewords = data
Or maybe
barcode = PDF417.new(:raw_codewords => data)
If that doesn't do it then it means digging into C code to fix it but I think the assumption you ran into is that it is passed a text string to be encoded, and that's a string with some very special characters.
Can you please explain how to convert hex data I'm trying to pass into element of raw_codewords
array?
Thanks!
Not any better than I have above - to set raw_codewords
pass it an array of the raw codewords.
What happens when this barcode is scanned, a bunch of binary data comes back?
I mean, How data in raw_codewords
is encoded?
For example
barcode = PDF417.new("test")
p barcode.codewords # [4, 829, 138, 599]
first element - length of array, what about other elements?
Yes, after scan binary data comes back.
Okay, looking at https://github.com/asee/pdf417/blob/master/ext/pdf417/pdf417.c#L189 and https://en.wikipedia.org/wiki/PDF417#Codewords it looks like the codewords should be integers and represent the binary data that has been encoded in the PDF417 format.
This gem is a wrapper around a C library and looking at the method it uses to convert text to codewords it looks like it will occasionally try to use compact binary codeword substitutes, but that it expects text data - https://github.com/asee/pdf417/blob/master/ext/pdf417/pdf417lib.c#L520
You need to fix your code. Problem: you setting ruby string to char array using StringValuePtr(text)
, but You don't set the right string size, RSTRING_LEN(text)
- will return the exact ruby string length. So, if you set p.lenText = (int)RSTRING_LEN(text);
there will be no problem :)
I've created a pull request to fix this, take a look.
That is great, thank you very much! It makes a log of sense now that you point it out too...
FYI, I bumped this up to 1.0.0, fixed some other errors that came up and released a new version of the gem
:+1:
Trying to create barcode with data:
data = ['08', 'FF', '00', '01', 'E2', '25', '01', '00', '00', '00', '00', '00', '00', 'CF', '21', '09', '2C', '16', 'E1', 'A0', '12', 'CE', '18', '00', '00']
barcode = PDF417.new([data.join].pack("H*"))
barcode stops with length of 4
if I delete '00' it will go thru
barcode = PDF417.new([data.delete_if { |x| x == '00' }.join].pack("H*"))
Is there any way to pass the data?