barnhill / barcode-java

Java Barcode Image Generation Library
MIT License
25 stars 14 forks source link

Get String encoded value #5

Closed sanmibuh closed 5 years ago

sanmibuh commented 5 years ago

Im trying to use the library for get the encoded value for use with a barcode font type.

If I get the encoded value (for example for Code128): new Code128(value).getEncodedValue()

Im getting a String with a binary content. For example I have this data: value - expected - encodedValue 0 - Ì01Î - 1101000010010011101100100111011001100011101011 93 -Í}ÃÎ - 1101001110010100011110101111010001100011101011 95 - ÍÃÅÎ - 1101001110010111101000111101010001100011101011 400000 - ÍHÂÂJÎ - 11010011100110001010001101100110011011001100101101110001100011101011

Any way to convert this binary output to a string for use with a barcode font type?

barnhill commented 5 years ago

Barcode font types are used to generate images correct? There is no need in using this library if you are using a barcode font. Likewise if you use this library there is no need for a font. The end goal is to get an image that is the barcode. If you call :

Barcode b = new Barcode();
Image img = barcode.encode(BarcodeLib.TYPE.CODE128, value);

You will get an image that you can put into image views or reports ... etc.

sanmibuh commented 5 years ago

Hi, you cannot write directly 93 with any font code type. You need to encode your String with the barcode system, in my case Code128.

So, for make a Code128 barcode with a barcode font type I must write Í}ÃÎ Now I using net.sf.barcode4j:barcode4j:2.1 dependency, that makes Gifs. But using his internals Im able to encode any test to Code128 encoding string. And with this string make the barcode with a barcode font (code128.ttf).

This library is unmaintained and the usage is not direct. I need to convert the output (int[]) to an ascii char[], and calculate the checksum for append it with the code128 stop character.

barnhill commented 5 years ago

Are you just trying to generate a barcode image? If so you are using two libraries when you can just use one. This library generates GIFs of a specified size given the data you want to encode and the symbology (C128) that you want to encode with. I dont understand why you would use both. It doesnt make any sense to me.

sanmibuh commented 5 years ago

I'm not generating a barcode gif. I'm generating a code128 encoded string for use with a barcode font(code128.ttf)

Because the lib I'm using is unmaintained, im looking for alternatives. I found your library, but I don't see any way for encoded a string to a code128 format.

barnhill commented 5 years ago

The format you speak of is not a standard that I know of. The encoding to an image is a standard. The encoded string representation that my library outputs in the meta data is for verification purposes and not for exporting to other libraries. The font you speak of the input format for that is probably proprietary. How are you using the font ... Maybe that would help me guide you.

Brad Barnhill, MSN, RN bradbarnhill@hotmail.com

On Thu, May 9, 2019, 12:45 PM David Belmez Vicente notifications@github.com wrote:

I'm not generating a barcode gif. I'm generating a code128 encoded string for use with a barcode font(code128.ttf)

Because the lib I'm using is unmaintained, im looking for alternatives. I found your library, but I don't see any way for encoded a string to a code128 format.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/barnhill/barcode-java/issues/5#issuecomment-491000290, or mute the thread https://github.com/notifications/unsubscribe-auth/AA5S2DSPJ3QSBAFEKKNAZPLPURPLZANCNFSM4HLG4ISA .

On Thu, May 9, 2019, 12:45 PM David Belmez Vicente notifications@github.com wrote:

I'm not generating a barcode gif. I'm generating a code128 encoded string for use with a barcode font(code128.ttf)

Because the lib I'm using is unmaintained, im looking for alternatives. I found your library, but I don't see any way for encoded a string to a code128 format.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/barnhill/barcode-java/issues/5#issuecomment-491000290, or mute the thread https://github.com/notifications/unsubscribe-auth/AA5S2DSPJ3QSBAFEKKNAZPLPURPLZANCNFSM4HLG4ISA .

sanmibuh commented 5 years ago

Hi, Im making the String using the code 128 barcode font character set:
https://www.idautomation.com/barcode-fonts/code-128/user-manual.html#Barcode_Font_Character_Set

barnhill commented 5 years ago

To give an analogy thats like taking a Chevrolet engine and trying to put Ford parts on it and wondering why it does not fit.

IdAutomation is a company not a standards organization like ISO. If you are using their font it tells you exactly what ascii or unicode char to use to get the desired output. My library generates images of barcodes given a dimension, data and symbology type. Im not sure how there was an expectation that encoding with one and then feeding meta data from it to another vendor will work at all.

sanmibuh commented 5 years ago

It is not the correct analogy: https://en.wikipedia.org/wiki/Code_128 You cannot write directly text with any barcode font. You need to transform it to code128 string. Idautomation page is correct. Maybe the pattern appears in the wikipedia page could help me.

barnhill commented 5 years ago

It most certainly is a correct analogy. The analogy refers to the use of meta data from this library being fed over to a proprietary font input expecting it to work. Its exactly like that.

There is no such thing as a "code128 string". There is only raw data and barcode output. There may be intermediary translations and meta data but those are not standards governed by ISO/IEC 15417:2007. IDAutomation is just doing the same thing my library does internally and mine converts the raw data to some string that has all the chars in it. Then it uses that to generate its images just like this library. What you want is for my library to expose that string of data with the control chars in it which is the format the font requires as fonts dont have any code to correctly format your data to work with them.

barnhill commented 5 years ago

Closing as this is an invalid use case of this library and not a good architectural decision even if it could be used this way.