boombuler / barcode

a barcode creation lib for golang
MIT License
1.41k stars 167 forks source link

Any way to get the checksum for code 128 barcodes? #7

Closed alexjg closed 8 years ago

alexjg commented 8 years ago

I'm writing an application which generates barcodes for logistics labels and one of the requirements is that the checksum from code 128 subset C barcode is printed on the label. Is there any easy way to access that value using this library?

boombuler commented 8 years ago

Hi,

the current API doesn't provide a way to access the checksum directly. And it only switches to C-Table if needed.

You may take a look at https://github.com/boombuler/barcode/blob/master/code128/encode.go#L117 In that line the checksum is written to the code.

If there is any way I could help you just let me know.

alexjg commented 8 years ago

Thanks for pointing that out. I suppose I could get the check digits by using some of the BitList operations then. I was wondering if it might make sense for it to be part of the API of the Barcode interface though, as a fair number of barcode specifications include check digits, and it's fairly common to print them on labels as human readable characters. I would be happy to do the work and put in a PR for Code 128 if it's something you would consider merging?

boombuler commented 8 years ago

Sure, I'll be happy to merge anything that could help other users of this module.

Though I'm not sure how that would look for QR or DataMatrix, since the checksum data is "weaved" with the data.

boombuler commented 7 years ago

Hi,

just to let you know, I've added an additional interface for those barcodes. (See: https://godoc.org/github.com/boombuler/barcode#BarcodeIntCS)

That way It's not needed to be implemented by all the other barcodes that don't support an integer checksum.

If you scale the barcode, the scaled barcode will also provide that interface. Hope thats OK with you and that it doesn't break your code. (Sorry for the API change...)