问题
Currently I'm programming a label-writer (Brother QL-570, if it matters, in Java) to print barcodes with different ID's. The length of the barcode data can vary from ~17 characters to ~3.
However, given that I've understood the barcode-concept correctly, the more data - the wider will the barcode become.
I'd prefer if all barcodes had the same, contstant size: no matter data-length. (It won't look good if the barcode doesn't fill up the label, nor will it (work) if it's too large)
How can one handle this when the labels are at a fixed size (i.e 29mm x 90mm)? How did you / your company solve this problem? 2D-barcodes aren't an option. Sadly.
回答1:
It's going to look kinda funny if you have to compare barcodes of different widths side-by-side, but my company solved it by defining each symbol in terms of a 1x?? bitmap and scaling it up to the size required for the application. For example, each code 128 symbol, except Stop, is eleven pixels wide. Our "font" then has 107 characters defined, each a 1x11 black and white bitmap (PNG).
It makes fitting the barcode into the space provided much simpler if you have that much control over vertical and horizontal dimensioning.
Here's a quick example similar to the picture up above:
<img
alt="104,{Start B}" title="104,{Start B}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AC3gAT0BDuLeG4IAAAAASUVORK5CYII=" width="30" height="30"><img
alt=" 17,A:{1},B:{1}" title=" 17,A:{1},B:{1}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AGMgAOkAhBjTObMAAAAASUVORK5CYII=" width="30" height="30"><img
alt=" 18,A:{2},B:{2}" title=" 18,A:{2},B:{2}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADGgAQUA0nI/mr0AAAAASUVORK5CYII=" width="30" height="30"><img
alt=" 19,A:{3},B:{3}" title=" 19,A:{3},B:{3}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADRgAMsAlQDS68kAAAAASUVORK5CYII=" width="30" height="30"><img
alt=" 08,A:{(},B:{(}" title=" 08,A:{(},B:{(}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AHNgAUkA1ElZCJAAAAAASUVORK5CYII=" width="30" height="30"><img
alt="106,{Stop}"title="106,{Stop}"src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAABAQMAAAA/57ZEAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADigARMA2dpJzT8AAAAASUVORK5CYII=" width="30" height="30">
<p/>
123
<br>
<p> </p>
<img
alt="104,{Start B}" title="104,{Start B}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AC3gAT0BDuLeG4IAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 17,A:{1},B:{1}" title=" 17,A:{1},B:{1}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AGMgAOkAhBjTObMAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 18,A:{2},B:{2}" title=" 18,A:{2},B:{2}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADGgAQUA0nI/mr0AAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 19,A:{3},B:{3}" title=" 19,A:{3},B:{3}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADRgAMsAlQDS68kAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 20,A:{4},B:{4}" title=" 20,A:{4},B:{4}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADYgAI8AVxcQlAsAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 21,A:{5},B:{5}" title=" 21,A:{5},B:{5}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ACNgAKkAhD/i5lYAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 22,A:{6},B:{6}" title=" 22,A:{6},B:{6}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADFgAMUAksTlwtMAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 23,A:{7},B:{7}" title=" 23,A:{7},B:{7}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ABIgAEcAM15OsZIAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 24,A:{8},B:{8}" title=" 24,A:{8},B:{8}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ABZgAI8Ad3Mh6bwAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 25,A:{9},B:{9}" title=" 25,A:{9},B:{9}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ABpgAJcAex9glyQAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 16,A:{0},B:{0}" title=" 16,A:{0},B:{0}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AGJgAScAw0BJukMAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 17,A:{1},B:{1}" title=" 17,A:{1},B:{1}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AGMgAOkAhBjTObMAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 18,A:{2},B:{2}" title=" 18,A:{2},B:{2}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADGgAQUA0nI/mr0AAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 19,A:{3},B:{3}" title=" 19,A:{3},B:{3}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADRgAMsAlQDS68kAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 20,A:{4},B:{4}" title=" 20,A:{4},B:{4}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADYgAI8AVxcQlAsAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 21,A:{5},B:{5}" title=" 21,A:{5},B:{5}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ACNgAKkAhD/i5lYAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 22,A:{6},B:{6}" title=" 22,A:{6},B:{6}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADFgAMUAksTlwtMAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 23,A:{7},B:{7}" title=" 23,A:{7},B:{7}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ABIgAEcAM15OsZIAAAAASUVORK5CYII=" width="9" height="30"><img
alt=" 64,A:{NUL},B:{`}" title=" 64,A:{NUL},B:{`}" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAABAQMAAAAy+cYDAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/AF5gAR8Av0A69KoAAAAASUVORK5CYII=" width="9" height="30"><img
alt="106,{Stop}"title="106,{Stop}"src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAABAQMAAAA/57ZEAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAADklEQVQIHQEDAPz/ADigARMA2dpJzT8AAAAASUVORK5CYII=" width="9" height="30">
<p/>
12345678901234567
Note that the dimensions are specified for each character and the barcodes will generally scan at a width of 8 or higher (depending on print quality). All characters within a barcode need identical widths. Remember that your horizontal quiet zone is a function of bar width, so try to keep at least two character widths to each side on the label.
回答2:
I think the best thing to do is pad your data, i.e.
123
Becomes
00000000000000123
Just from thinking about how other places do it, I've definitely seen zero padded barcodes in my day-to-day life before. I think the best thing to do is just pick a number of digits that you think will be sufficient for years and code your application to that number. If you end up having to go beyond it, well, that's a good problem to have, isn't it?
来源:https://stackoverflow.com/questions/13768651/how-to-achieve-constant-width-for-barcodes-regardless-of-barcode-data